group by
case when convert(char(5),inputDateTime,108) between '00:00' and '02:59' then 1
convert(char(5),inputDateTime,108) between '03:00' and '05:59' then 2
...
end
case when convert(char(5),inputDateTime,108) between '00:00' and '02:59' then 1
convert(char(5),inputDateTime,108) between '03:00' and '05:59' then 2
...
end
where (DATEDIFF([day], inputDateTime, '9/29/2005') = 0)
and DealReturnSMS like '尊敬的用户%'
group by machineid,DatePart(hour,inputDateTime)
order by machineid
datepart(hour,date_col)