首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

group by 结果怎么新增一行

2012-03-11 
group by 结果如何新增一行selectb.region as 城区/单位,count(case when month(a.adddate)1 then a.re

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

热点排行