sql如下,当前取得是每一天的早八到晚八的数据,怎么才能取当天晚八到第二天早八的数据呢

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

FineReport Vessel1213 发布于 2023-2-17 17:18
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2023-2-17 17:24

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 '${FORMAT(kssj,"yyyy-MM-dd 20:00:00")}' and '${FORMAT(jssj,"yyyy-MM-dd 08:00:00")}'

and left(Start,2) !='XS'

--and SUBSTRING(ReqTime,12,2)>='08'and SUBSTRING(ReqTime,12,2)<'20'

) a

group by s,dt

最佳回答
1
fine工具人Lv5见习互助
发布于2023-2-17 17:30(编辑于 2023-2-17 18:24)

and SUBSTRING(ReqTime,12,2) in('20','21','22','23','24','00','01','02','03','04','05','06','07')

或者

and (SUBSTRING(ReqTime,12,2)<'08' or SUBSTRING(ReqTime,12,2)>='20')

  • 2关注人数
  • 349浏览人数
  • 最后回答于:2023-2-17 18:24
    请选择关闭问题的原因
    确定 取消
    返回顶部