我有一张桌子“记录”
[记录] [1]
select typeofservice,
Coalesce(sum(incomecost,expensecost),0) 'incomecost,expensecost'
from records
where dateoftrans = '2016-11-22'
group by typeofservice with rollup;
我希望能够在第二张图片上显示结果,这是我的查询...,所有这些交易都发生在一天之内。请帮忙
https://i.stack.imgur.com/fLYav.png
最佳答案
如果仅用于第二张图像的结果,则可以这样尝试sum(incomecost)
和sum(expensecost)
:
SELECT
typeofservice,
Coalesce(SUM(incomecost), 0) AS incomecost,
Coalesce(SUM(expensecost), 0) AS expensecost
FROM records
GROUP BY typeofservice
WITH ROLLUP
关于mysql - 获取同一列多个行的总值和两个不同行的总和(mysql查询),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40737284/