分天小时段 汇总数据
select (cast(convert(varchar(100),dtime,23) as varchar(10))+':'+(case when len(cast(datepart(hour,convert(datetime,dtime))as varchar(4)))<2
then '0'+cast(datepart(hour,convert(datetime,dtime))as varchar(4))
else cast(datepart(hour,convert(datetime,dtime))as varchar(4)) end)as gtime,
count(*) as number from oplog where dtime between '2011-02-03 12:13:000' and '2011-08-03 12:13:000'
group by (cast(convert(varchar(100),dtime,23) as varchar(10))+':'+(case when len(cast(datepart(hour,convert(datetime,dtime))as varchar(4)))<2
then '0'+cast(datepart(hour,convert(datetime,dtime))as varchar(4))
else cast(datepart(hour,convert(datetime,dtime))as varchar(4)) end) order by gtime asc
统计一段时间内各小时段数据
select (case when len(cast(datepart(hour,convert(datetime,dtime))as varchar(4)))<2
then '0'+cast(datepart(hour,convert(datetime,dtime))as varchar(4))
else cast(datepart(hour,convert(datetime,dtime))as varchar(4)) end) as gtime,
count(*) as number from oplog where dtime between '2012-1-17' and '2012-5-17'
group by (case when len(cast(datepart(hour,convert(datetime,dtime))as varchar(4)))<2
then '0'+cast(datepart(hour,convert(datetime,dtime))as varchar(4))
else cast(datepart(hour,convert(datetime,dtime))as varchar(4)) end)
order by gtime asc