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

请问记录集设置有关问题

2013-03-04 
请教记录集设置问题请教大侠这样设计的SQL记录集是如何设置的?如:表1ID评价人评价时间111好评2013-1-1211

请教记录集设置问题
请教大侠这样设计的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

热点排行