数据表AAA
A B
a aa
b bb
c cc
c dd
select A,count(B) from AAA group A
结果:
a 1
b 1
c 2
现在我想把结果变成带个合计,也就是
a 1
b 1
c 2
合计 4
有没有用办法用SQL语句实现?
declare @t table(A varchar(20),B varchar(50))
insert @t
select 'a', 'aa'
union all
select 'b','bb'
union all
select 'c', 'cc'
union all
select 'c', 'dd'
select case when grouping(A)=1 then '合计' else A end,count(1)
from @t
group by A with cube
union all select 'cont',Count(num) from table