gpt4 book ai didi

Mysql 查询加减法

转载 作者:行者123 更新时间:2023-11-29 15:43:34 25 4
gpt4 key购买 nike

select
sum(Account_recharge) as 'Total Recharge',
sum(Amount_Received) as 'Total Received'
from insert1
cross join received1
on insert1.id = received1.id
where insert1.Account_Name = 'arvind2';

total recharge Total received
1000 500

但我还想显示会费=500

最佳答案

取充值总额与收到总额的差额?

SELECT
SUM(Account_recharge) AS `Total Recharge`,
SUM(Amount_Received) AS `Total Received`,
SUM(Account_recharge) - SUM(Amount_Received) AS dues
FROM insert1 i1
INNER JOIN received1 r1
ON i1.id = r1.id
WHERE
i1.Account_Name = 'arvind2';

请注意,我用内部联接替换了交叉联接。交叉连接在这里没有意义,因为连接有一个标准(尽管显然它在 MySQL 中为您工作)。

关于Mysql 查询加减法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com