4.3 KiB
4.3 KiB
항차별 통계 (작업중)
SELECT yyyymm
FROM ( SELECT TO_CHAR(ADD_MONTHS('2021-01-01', -1 + LEVEL), 'YYYYMM') AS yyyymm
FROM DUAL
CONNECT BY LEVEL <= 100) cal
WHERE cal.yyyymm BETWEEN substr(:arFromDT,1,6) AND substr(:arToDT,1,6)
SELECT to_char(last_day(:ar_stdym||'01'), 'yyyymmdd')||'235959' FROM dual
/*
출항-입항일시가 기준년월(3월) 이내에 포함되는 모든 선박
3월중에 출항, 3월 입항
3월중에 출항, 3월 미입항
3월이전 출항, 3월 입항
3월이전 출항, 3월 미입항
and TKOFF_DE >= :ar_stdym||'01' AND (nvl(ETRYPT_DE, '99991231') <= :ar_stdym||'31' or nvl(ETRYPT_DE,:ar_stdym||'31') > :ar_stdym||'31' )
or TKOFF_DE < :ar_stdym||'01' AND ( ( nvl(ETRYPT_DE, '99991231') >= :ar_stdym||'31' and nvl(ETRYPT_DE, '99991231') <= :ar_stdym||'31' ) or nvl(ETRYPT_DE,:ar_stdym||'31') > :ar_stdym||'31' )
*/
SELECT :ar_stdym AS yyyymm,
A.SHIP_NO,
A.SLOT_NO,
A.CALL_SIGN,
A.SHIP_NAME,
B.OUT_DT,
B.IN_DT,
b.days,
cnv_IN_dt,
cnv_OUT_dt,
to_date(cnv_IN_dt, 'yyyymmddhh24miss')
- to_date(cnv_OUT_dt, 'yyyymmddhh24miss') AS cnv_days
FROM ( SELECT FSHRBT_NO SHIP_NO,
TKOFF_DE||TKOFF_TIME AS out_dt,
ETRYPT_DE||NVL(ETRYPT_TIME, '235959') AS in_dt,
CASE WHEN TKOFF_DE < :ar_stdym||'01' THEN :ar_stdym||'01000000' ELSE TKOFF_DE||TKOFF_TIME END AS cnv_OUT_dt,
CASE WHEN nvl(ETRYPT_DE,'99991231') > :ar_stdym||'31' THEN to_char(last_day(:ar_stdym||'01'), 'yyyymmdd')||'235959' ELSE ETRYPT_DE||NVL(ETRYPT_TIME, '235959') END AS cnv_IN_dt,
to_date(ETRYPT_DE||NVL(ETRYPT_TIME, '235959'), 'yyyymmddhh24miss')
- to_date(TKOFF_DE||TKOFF_TIME, 'yyyymmddhh24miss') AS days
FROM TACEEZ.TB_FBB_TKOFF@TACEEZ_LINK a
WHERE FSHRBT_NO IS NOT NULL
AND TKOFF_DE IS NOT NULL
AND TKOFF_TIME IS NOT NULL
AND TKOFF_DE > '20200101'
AND substr(nvl(TKOFF_DE,'999999'),5,2) < '13'
AND substr(nvl(ETRYPT_DE,'999999'),5,2) < '13'
AND (
-- 기준월에 출항 ~ 기준월 입항했거나 기준월 이후입항
( substr(TKOFF_DE, 1,6) = :ar_stdym AND (substr(nvl(ETRYPT_DE,:ar_stdym), 1,6) >= :ar_stdym )
) OR
-- 기준월 이전에 출항 ~ 기준월 입항했거나 기준월 이후입항
( substr(TKOFF_DE, 1,6) < :ar_stdym AND (substr(nvl(ETRYPT_DE,:ar_stdym), 1,6) >= :ar_stdym )
)
) -- AND END
) b , MV_ARS_SHIP A
WHERE A.SHIP_NO = B.SHIP_NO
AND a.slot_no IS NOT NULL
AND a.SHIP_NO = '00090036267104'
SELECT sub.yyyymm,
sub.SHIP_NO,
sub.SLOT_NO,
sub.CALL_SIGN,
sub.SHIP_NAME,
sum(sub.cnv_days) AS cnv_days
FROM (
SELECT :ar_stdym AS yyyymm,
A.SHIP_NO,
A.SLOT_NO,
A.CALL_SIGN,
A.SHIP_NAME,
to_date(cnv_IN_dt, 'yyyymmddhh24miss')
- to_date(cnv_OUT_dt, 'yyyymmddhh24miss') AS cnv_days
FROM ( SELECT FSHRBT_NO SHIP_NO,
TKOFF_DE||TKOFF_TIME AS out_dt,
ETRYPT_DE||NVL(ETRYPT_TIME, '235959') AS in_dt,
CASE WHEN TKOFF_DE < :ar_stdym||'01' THEN :ar_stdym||'01000000' ELSE TKOFF_DE||TKOFF_TIME END AS cnv_OUT_dt,
CASE WHEN nvl(ETRYPT_DE,'99991231') > :ar_stdym||'31' THEN to_char(last_day(:ar_stdym||'01'), 'yyyymmdd')||'235959' ELSE ETRYPT_DE||NVL(ETRYPT_TIME, '235959') END AS cnv_IN_dt,
to_date(ETRYPT_DE||NVL(ETRYPT_TIME, '235959'), 'yyyymmddhh24miss')
- to_date(TKOFF_DE||TKOFF_TIME, 'yyyymmddhh24miss') AS days
FROM TACEEZ.TB_FBB_TKOFF@TACEEZ_LINK a
WHERE FSHRBT_NO IS NOT NULL
AND TKOFF_DE IS NOT NULL
AND TKOFF_TIME IS NOT NULL
AND TKOFF_DE > '20200101'
AND substr(nvl(TKOFF_DE,'999999'),5,2) < '13'
AND substr(nvl(ETRYPT_DE,'999999'),5,2) < '13'
AND (
-- 기준월에 출항 ~ 기준월 입항했거나 기준월 이후입항
( substr(TKOFF_DE, 1,6) = :ar_stdym AND (substr(nvl(ETRYPT_DE,:ar_stdym), 1,6) >= :ar_stdym )
) OR
-- 기준월 이전에 출항 ~ 기준월 입항했거나 기준월 이후입항
( substr(TKOFF_DE, 1,6) < :ar_stdym AND (substr(nvl(ETRYPT_DE,:ar_stdym), 1,6) >= :ar_stdym )
)
) -- AND END
) b , MV_ARS_SHIP A
WHERE A.SHIP_NO = B.SHIP_NO
AND a.slot_no IS NOT NULL
AND a.SHIP_NO = '00090036267104'
) sub
GROUP BY sub.yyyymm,
sub.SHIP_NO,
sub.SLOT_NO,
sub.CALL_SIGN,
sub.SHIP_NAME
ORDER BY ship_no