SQL server 按白夜班查询报警数据

阅读: 评论:0

SQL server 按白夜班查询报警数据

SQL server 按白夜班查询报警数据

SQL实例代码

1.按照时间段、班次查询数据

--按时间段、班次查询数据
select * from (select Line,Machine,Adress,Adress_num, UpStart_time,UpEnd_time,CONVERT (CHAR(10), UpStart_time, 120)as DATATIME,BC=case when datename(hour,UpStart_time)<8 or datename(hour,UpStart_time)>=20 then '夜班' else '白班' endfrom B10_ALM_Data_Record_History )A where A.BC='白班' and A.DATATIME between '2022-10-31' and '2022-10-31'
union all
select * from (select Line,Machine,Adress,Adress_num, UpStart_time,UpEnd_time,CONVERT (CHAR(10), UpStart_time, 120)as DATATIME,BC=case when datename(hour,UpStart_time)<8 or datename(hour,UpStart_time)>=20 then '夜班' else '白班' endfrom B10_ALM_Data_Record )A where A.BC='白班' and A.DATATIME between '2022-10-31' and '2022-10-31'

查询结果

2.按年、班次查询数据

--按年、班次查询数据select * from (select Line,Machine,Adress,Adress_num, UpStart_time,UpEnd_time,CONVERT (CHAR(10), UpStart_time, 120)as DATATIME,BC=case when datename(hour,UpStart_time)<8 or datename(hour,UpStart_time)>=20 then '夜班' else '白班' endfrom B10_ALM_Data_Record_History )A where A.BC='夜班' and year(A.DATATIME)='2022'

3.按月、班次查询数据

--按月、班次查询数据
select * from (select Line,Machine,Adress,Adress_num, UpStart_time,UpEnd_time,CONVERT (CHAR(10), UpStart_time, 120)as DATATIME,BC=case when datename(hour,UpStart_time)<8 or datename(hour,UpStart_time)>=20 then '夜班' else '白班' endfrom B10_ALM_Data_Record_History )A where A.BC='夜班' and month(A.DATATIME)='11'

4.按照日、班次查询

--按照日、班次查询
select * from (select Line,Machine,Adress,Adress_num, UpStart_time,UpEnd_time,CONVERT (CHAR(10), UpStart_time, 120)as DATATIME,BC=case when datename(hour,UpStart_time)<8 or datename(hour,UpStart_time)>=20 then '夜班' else '白班' endfrom B10_ALM_Data_Record_History )A where A.BC='夜班' and A.DATATIME='2022-11-05'

说明:按照周的暂时未写

本文发布于:2024-01-31 00:00:45,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170663044423781.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:白夜   数据   SQL   server
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23