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小时内删除。
留言与评论(共有 0 条评论) |