你能幫我換班嗎?我需要爲每個事件分配它是什麼。 我想統計在每個班次中機器完成多少項目。 「ILE」的意思是「有多少項目移位共做」甲骨文輪班工作日期
SELECT lz.EVENT,
TO_CHAR(lz.DATA_ZATW, 'YYYY-MM-DD') AS DATA,
CASE WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI') BETWEEN '06:00' AND '13:59' THEN 'First Shift'
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI') BETWEEN '14:00' AND '21:59' THEN 'Second Shift'
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI') BETWEEN '22:00' AND '23:59' THEN 'Third Shift'
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI') BETWEEN '00:00' AND '05:59' THEN 'Third Shift'
END AS SHIFT
FROM PLC.LIST lz;
但是當我現在檢查查詢和我有2017年8月3日第三次轉變,這是錯誤的,因爲根據SYSDATE我shound必須先轉變只要。 有什麼想法?
編輯:
整個查詢
SELECT "DATA",
"ZMIANA",
"SOV_GAO_1_ILE",
"SOV_GAD_2_ILE",
"SOV_GAM_3_ILE"
FROM (SELECT TO_CHAR(lz.DATA_ZATW, 'YYYY-MM-DD') AS DATA,
CASE WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI:SS') BETWEEN '06:00:00' AND '13:59:59.999999' THEN 1
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI:SS') BETWEEN '14:00:00' AND '21:59:59.999999' THEN 2
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI:SS') BETWEEN '22:00:00' AND '23:59:59.999999' THEN 3
WHEN TO_CHAR(lz.DATA_ZATW, 'HH24:MI:SS') BETWEEN '00:00:00' AND '05:59:59.999999' THEN 3
END AS ZMIANA,
lz.LINIA,
lz.DETAL
FROM PLC.LISTA_ZDARZEN lz
GROUP BY lz.DATA_ZATW,
lz.LINIA,
lz.DETAL) PIVOT (COUNT(DETAL) AS ILE FOR LINIA IN ('SOV_GAO_1' SOV_GAO_1, 'SOV_GAD_2' SOV_GAD_2, 'SOV_GAM_3' SOV_GAM_3));
編輯:
轉變
6-14 01.08 first shift
14-22 01.08 second shift
22-00 01.08 third shift
00-6 02.08 third shift
6-14 02.08 first shift
14-22 02.08 second shift
22-00 02.08 third shift
00-6 03.08 third shift
6-14 03.08 first shift
14-22 03.08 second shift
22-00 03.08 third shift
00-6 04.08 third shift
這裏時間:
SELECT TO_DATE('2017-08-01 23:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 01.08 Third shift
SELECT TO_DATE('2017-08-01 23:57:58', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 01.08 Third shift
SELECT TO_DATE('2017-08-02 03:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 01.08 Third shift
SELECT TO_DATE('2017-08-02 04:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 01.08 Third shift
SELECT TO_DATE('2017-08-02 06:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 First shift
SELECT TO_DATE('2017-08-02 07:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 First shift
SELECT TO_DATE('2017-08-02 10:24:34', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 First shift
SELECT TO_DATE('2017-08-02 14:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Second shift
SELECT TO_DATE('2017-08-02 15:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Second shift
SELECT TO_DATE('2017-08-02 19:21:10', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Second shift
SELECT TO_DATE('2017-08-02 22:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-02 23:55:20', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-02 23:55:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-03 00:02:34', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-03 00:05:34', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-03 00:10:38', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 02.08 Third shift
SELECT TO_DATE('2017-08-03 09:01:24', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 03.08 First shift
SELECT TO_DATE('2017-08-03 09:01:32', 'yyyy-mm-dd hh24:mi:ss') FROM DUAL UNION ALL -- 03.08 First shift
SELECT TO_DATE('2017-08-03 17:01:10', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 03.08 Second shift
SELECT TO_DATE('2017-08-03 19:28:45', 'yyyy-mm-dd hh24:mi:ss') FROM DUAL UNION ALL -- 03.08 Second shift
SELECT TO_DATE('2017-08-03 23:54:56', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 03.08 Third shift
SELECT TO_DATE('2017-08-03 23:55:20', 'yyyy-mm-dd hh24:mi:ss') FROM dual UNION ALL -- 03.08 Third shift
SELECT TO_DATE('2017-08-03 23:55:56', 'yyyy-mm-dd hh24:mi:ss') FROM DUAL -- 03.08 Third shift
請提供一些示例數據和預期的結果。 – APC
嘗試'TO_CHAR(lz.DATA_ZATW,'YYYY-MM-DD HH24:MI:SS')AS DATA'以驗證您的CASE表達式。 –
我只想計算每個班次機器完成多少項目。 –