日期:2014-05-16  浏览次数:20950 次

汇总统计,如何得到分类汇总结果的和
我现在在做分类汇总统计,
例如:Select name,count(id) as num from table1 group by name 
结果为:
name num
aaaa 2
bbbb 3
cccc 7

我想获取汇总结果的和,就是自动计算累加值,生成以下结果:
name num
aaaa 2
bbbb 3
cccc 7
sum 12

不知道怎么写SQL语句?



------解决方案--------------------
SQL code
Select name,count(id) as num from table1 group by name  
union all
Select 'sum',count(id) as num from table1

------解决方案--------------------
Select name,count(id) as num from table1 group by name
union all
Select 'sum',count(id) as num from table1