select A,count(B) from AAA group A 结果: a 1 b 1 c 2
现在我想把结果变成带个合计,也就是 a 1 b 1 c 2 合计 4
有没有用办法用SQL语句实现?
慕斯王
浏览 425回答 2
2回答
慕姐8265434
declare @t table(A varchar(20),B varchar(50))insert @tselect 'a', 'aa'union allselect 'b','bb'union allselect 'c', 'cc'union allselect 'c', 'dd'select case when grouping(A)=1 then '合计' else A end,count(1)from @tgroup by A with cube