group by 结果如何新增一行
select
b.region as '城区/单位',
count(case when month(a.adddate)=1 then a.region end) as '1月发稿',
count(case when month(a.adddate)=2 then a.region end) as '2月发稿',
count(case when month(a.adddate)=3 then a.region end) as '3月发稿',
count(case when month(a.adddate)=4 then a.region end) as '4月发稿 ',
count(case when month(a.adddate)=5 then a.region end) as '5月发稿 ',
count(case when month(a.adddate)=6 then a.region end) as '6月发稿 ',
count(case when month(a.adddate)=7 then a.region end) as '7月发稿 ',
count(case when month(a.adddate)=8 then a.region end) as '8月发稿 ',
count(case when month(a.adddate)=9 then a.region end) as '9月发稿 ',
count(case when month(a.adddate)=10 then a.region end) as '10月发稿 ',
count(case when month(a.adddate)=11 then a.region end) as '11月发稿 ',
count(case when month(a.adddate)=12 then a.region end) as '12月发稿 ',
count(case when month(a.adddate)=1 then a.region end)+count(case when month(a.adddate)=2 then a.region end)+
count(case when month(a.adddate)=3 then a.region end)+count(case when month(a.adddate)=4 then a.region end)+
count(case when month(a.adddate)=5 then a.region end)+count(case when month(a.adddate)=6 then a.region end)+
count(case when month(a.adddate)=7 then a.region end)+count(case when month(a.adddate)=8 then a.region end) +
count(case when month(a.adddate)=9 then a.region end)+count(case when month(a.adddate)=10 then a.region end)+
count(case when month(a.adddate)=11 then a.region end)+count(case when month(a.adddate)=12 then a.region end) as 全年发稿
from nnedu_article a,nnedu_region b where a.region=b.region_id
and year(a.adddate)='2011'
group by b.region_id,b.region
order by b.region_id
运行结果如下:
现在想在统计结果下加一行,统计每个月发帖的总数
------解决方案--------------------union all
select sum(),......
------解决方案--------------------
with rollup