select '00:00-00:59' as Time, count=(select count(1) from tb where datepart(hh,Tdate)<1) union all select '01:00-01:59' as Time, count=(select count(1) from tb where datepart(hh,Tdate)>=1 and datepart(hh,Tdate)<2) union all select '02:00-03:59' as Time, count=(select count(1) from tb where datepart(hh,Tdate)>=2 and datepart(hh,Tdate)<3)....
--做个临时表存时间的。 create table #temp(stutime varchar(10),endtime varchar(10)) insert into #temp select '00:00','00:59' union all .... select '23:00','23:59' go--然后用临时表和你的表结合来做!
select '00:00-00:59' as Time,
count=(select count(1) from tb where datepart(hh,Tdate)<1)
union all
select '01:00-01:59' as Time,
count=(select count(1) from tb where datepart(hh,Tdate)>=1 and datepart(hh,Tdate)<2)
union all
select '02:00-03:59' as Time,
count=(select count(1) from tb where datepart(hh,Tdate)>=2 and datepart(hh,Tdate)<3)....
--做个临时表存时间的。
create table #temp(stutime varchar(10),endtime varchar(10))
insert into #temp
select '00:00','00:59' union all
....
select '23:00','23:59'
go--然后用临时表和你的表结合来做!