Das war keine große Query, das ist eine große Query (und ja, die ist produktiv und wird alle 5 Minuten ausgeführt):
SQL:
SELECT
CASE
WHEN ( TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') < TO_DATE(CONCAT(vsdkpdt,vsdkztvon), 'YYYYMMDDHH24MISS') )
THEN CASE
WHEN (TO_DATE(CONCAT(vsdkpdt,vsdkztvon), 'YYYYMMDDHH24MISS')+1/24) >= TO_DATE(anflts_end, 'YYMMDDHH24MISS') THEN 0
ELSE 1
END
WHEN ( TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') >= TO_DATE(CONCAT(vsdkpdt,vsdkztvon), 'YYYYMMDDHH24MISS') AND TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') <= TO_DATE(CONCAT(vsdkpdt,vsdkztbis), 'YYYYMMDDHH24MISS') )
THEN CASE
WHEN (TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') +1/24) >= TO_DATE(anflts_end, 'YYMMDDHH24MISS') THEN 0
ELSE 1
END
WHEN ( TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') >= TO_DATE(CONCAT(vsdkpdt,vsdkztbis), 'YYYYMMDDHH24MISS') )
THEN 2
ELSE 2
END Problemcode,
vlkw.vlkwkz Kennzeichen,
sped.spedkx Spedition,
ROUND((TO_DATE(vlkw_a0z, 'YYYYMMDDHH24MISS') - TO_DATE(CONCAT(vsdkpdt,vsdkztvon), 'YYYYMMDDHH24MISS') )*24*60) Verspätung_LKW,
ABS(ROUND((TO_DATE(vlkw_a0z , 'YYYYMMDDHH24MISS') - TO_DATE(anflts_end, 'YYYYMMDDHH24MISS'))*24*60)) ladezeit,
(CONCAT(vsdkpdt,vsdkztvon)) ladefenster_von,
(CONCAT(vsdkpdt,vsdkztbis)) ladefenster_bis,
(vlkw_a0z) LKW_Ankunft,
(anflts_end) Ende
FROM
(SELECT vlkwid, anflts_end FROM anfl WHERE anfl.anftid = 'VSLKW'
UNION
SELECT vlkwid, anflts_end FROM anfl_arch WHERE anftid = 'VSLKW'
) anfl
LEFT JOIN vlkw ON vlkw.vlkwid = anfl.vlkwid
LEFT JOIN vlad ON vlad.vlkwid = vlkw.vlkwid
LEFT JOIN vsdk ON vsdk.vladid = vlad.vladid
LEFT JOIN sped ON sped.spednr = vlkw.spednr
WHERE TRIM(anflts_end) IS NOT NULL AND TRIM(vsdkztvon) IS NOT NULL AND vlkw_a0z >= @DT(yyyyMM;M-1)
GROUP BY
vlkw.vlkwid,
vlkw.vlkwkz,
sped.spedkx,
vsdkpdt,
vsdkztvon,
vsdkztbis,
vlkw_a0z,
anflts_end
ORDER BY vlkw_a0z DESC