请问怎样用SQL语句分组 按照 [类型]来分组 小计 ,比如同一个类型的就分一组小计[金额],最后就总计

2025-01-05 15:22:13
推荐回答(2个)
回答1:

Select ID,name,no,
(Case When Kind Is null And ID Is Null Then '总计:'
When ID Is Null Then '小计:' Else Kind End) As Kind,
Sum(jine) jine,class
From 表名
Group By Grouping Sets((id,name,no,kind,class),(kind),())

回答2:

select kind,jine,sum(jine),grouping(kind) from 表名 group by kind,jine with ROLLUP 这么写就可以了