gpt4 book ai didi

mysql - 获取同一列多行的总值和两行不同的总和(mysql查询)

转载 作者:行者123 更新时间:2023-11-30 22:09:01 26 4
gpt4 key购买 nike

我有一个表“记录”[记录][1]

select typeofservice, 
Coalesce(sum(incomecost,expensecost),0) 'incomecost,expensecost'
from records
where dateoftrans = '2016-11-22'
group by typeofservice with rollup;

我希望能够在第二张图片上获得结果,这是我的查询...所有这些交易都发生在一天之内。请帮忙

/image/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/

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