我是Mysql Db中的新蜜蜂你可以帮助我从当前表中获取输出。
请检查表结构和输出的给定链接
答案 0 :(得分:2)
使用GROUP BY
,SUM
和CASE
(或IF):
SELECT Buyer, TotalAmount, PaidAmount, TotalAmount-PaidAmount BalanceAmount
FROM (
SELECT Buyer,
SUM(Amount) TotalAmount,
SUM(CASE WHEN PaidStatus = 1 THEN Amount ELSE 0 END) PaidAmount
FROM YourTable
GROUP BY Buyer
) t