現在用mysql陳述句查詢,查詢的時每天時間段內的記錄,但是用時比較久,有沒有大佬能簡化一下查詢陳述句,
需要查詢兩個表,兩個表的結構完全相同,所以在這里做了一個拼接。
陳述句如下:
select jobNumber,
Date,
Area,
cellNo,
shift,
Name,
originalArea,
originalCell,
accQty,
transferDetail,
classesID,
adjusDown,
adjueCard
from ((select `job_number` as jobNumber,
Date,
Area,
cell_no as cellNo,
shift,
Name,
Original_Area as originalArea,
Original_Cell as originalCell,
ACC_Qty as accQty,
Transfer_Detail as transferDetail,
`Classes ID` as classesID,
`Adjus-統一下班` as adjusDown,
`Adjus-補卡` as adjueCard
from accendance_all
where ID not in (select ID from accendance_all where Date < '2021-03-01 10:00:00' and Shift = '夜班')
and ID not in (select ID from accendance_all where Date > '2021-03-01 23:00:00' and Shift = '白班')
and date between '2021-03-01 06:00:00' and '2021-3-02 10:00:00')
union
(select `job_number` as jobNumber,
Date,
Area,
cell_no as cellNo,
shift,
Name,
Original_Area as originalArea,
Original_Cell as originalCell,
ACC_Qty as accQty,
Transfer_Detail as transferDetail,
`Classes ID` as classesID,
`Adjus-統一下班` as adjusDown,
`Adjus-補卡` as adjueCard
from accendance_list
where ID not in (select ID from accendance_list where Date < '2021-03-01 10:00:00' and Shift = '夜班')
and ID not in (select ID from accendance_list where Date > '2021-03-01 23:00:00' and Shift = '白班')
and date between '2021-03-01 06:00:00' and '2021-3-02 10:00:00')) a
order by a.jobNumber, a.Date asc;
uj5u.com熱心網友回復:
您方便把要實作什么功能說一下嗎?我知道你實作了 但是我一行行看 看的暈 不方便就算了轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/264927.html
標籤:MySQL
上一篇:計算最低價天數的SQL陳述句
下一篇:ETL薪資
