select s,sum(gs) as num,dt from (select case when left(Start,2)='XS'then Start else left(Start,2) end s,DATEDIFF(ss,ReqTime,EndTime) as gs ,CONVERT(NVARCHAR(10),ReqTime) as dt--ReqTime,EndTime from test where ReqTime is not null and [ReqTime] between '${kssj}' and '${jssj}' and left(Start,2) !='XS' and SUBSTRING(ReqTime,12,2)>='08'and SUBSTRING(ReqTime,12,2)<'20' ) a group by s,dt |