select dt,newDate,sum(state) counts from (
select
convert(varchar(10),createDate,120) as dt,state,
case when createDate>=cast((convert(varchar(10),createDate,120)+'') as datetime)
and createDate<cast((convert(varchar(10),createDate,120)+' 09:00:00.000') as datetime)
then 1
when createDate>=cast((convert(varchar(10),createDate,120)+' 09:00:00.000') as datetime)
and createDate<cast((convert(varchar(10),createDate,120)+' 18:00:00.000') as datetime)
then 2
when createDate>=cast((convert(varchar(10),createDate,120)+' 18:00:00.000') as datetime)
and createDate<cast((convert(varchar(10),createDate,120)+' 23:59:59.999') as datetime)
then 3
else 4 end newDate
from questionInfo ) o
group by dt,newDate
order by dt
日期时间以天为单位统计小时区间时间段数据
最新推荐文章于 2022-11-26 06:52:15 发布