显示年度事务

bnl4lu3b  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(315)

如果汇总总数为“500”,我希望结果显示为“总计”,而不是当前显示为“空”
另外,我不确定如何添加where子句以仅查看2018年期间处理的交易?
有什么想法吗?谢谢您

select date_format(TRANSACTION_DATE, '%M') AS MONTH, 
SUM(SALES_AMOUNT) TOTAL
FROM SALES
GROUP BY DATE_FORMAT(TRANSACTION_DATE, '%M') WITH ROLLUP

January 160.00
June    100.00
May     240.00
Null    500.00
gk7wooem

gk7wooem1#

这对我很有用:
http://www.sqlfiddle.com/#!18/8647e/4号

SELECT 
isnull(datename(month, [Date1]), 'Total'),
SUM([Amount])
FROM Table1
GROUP BY datename(month , [Date1]) WITH ROLLUP

结果:

|         |     |
|---------|-----|
| January | 160 |
|    June | 100 |
|     May | 240 |
|   Total | 500 |

相关问题