请教记录集设置问题
请教大侠这样设计的SQL记录集是如何设置的?
如:表1
ID 评价人 评价 时间
1 11 好评 2013-1-1
2 11 好评 2013-1-5
3 11 好评 2013-1-6
4 11 好评 2013-1-7
5 11 中评 2013-1-11
6 11 好评 2013-1-12
7 11 好评 2013-1-15
8 11 好评 2013-1-16
------解决方案--------------------select
case when grouping(评价)=1 then '总计' else cast(评价 as varchar) end,
sum(case when datediff(ww,时间,getdate())=0 then 1 else 0 end) as '最近1周',
sum(case when datediff(m,时间,getdate())=0 then 1 else 0 end) as '最近1月',
sum(case when datediff(m,时间,getdate())<7 then 1 else 0 end) as '最近6个月',
sum(case when datediff(m,时间,getdate())>6 then 1 else 0 end) as '6个月前',
count(*) as 合计
from 表1
group by 评价
with rollup