代码改变世界

分时段统计登录系统人数

2010-11-15 11:30  hailibu  阅读(325)  评论(0编辑  收藏  举报

 

select 
sum(case when DatePart(hh,finputtime)=1 then 1 else 0 end) as '1:00~2:00', 
sum(case when DatePart(hh,finputtime)=2 then 1 else 0 end) as '2:00~3:00', 
sum(case when DatePart(hh,finputtime)=3 then 1 else 0 end) as '3:00~4:00', 
sum(case when DatePart(hh,finputtime)=4 then 1 else 0 end) as '4:00~5:00',  
sum(case when DatePart(hh,finputtime)=5 then 1 else 0 end) as '5:00~6:00', 
sum(case when DatePart(hh,finputtime)=6 then 1 else 0 end) as '6:00~7:00', 
sum(case when DatePart(hh,finputtime)=7 then 1 else 0 end) as '7:00~8:00', 
sum(case when DatePart(hh,finputtime)=8 then 1 else 0 end) as '8:00~9:00', 
sum(case when DatePart(hh,finputtime)=9 then 1 else 0 end) as '9:00~10:00', 
sum(case when DatePart(hh,finputtime)=10 then 1 else 0 end) as '10:00~11:00',
sum(case when DatePart(hh,finputtime)=11 then 1 else 0 end) as '11:00~12:00'
from S_Exam_LoginInfo where finputtime  >=convert(varchar(10),getdate(),120)