-- 원본 쿼리입니다.
SELECT
D2.DPRT_NM
D2.DPRT_CD
D2.DPRT_SRTN_SQNC
SUM(CASE_WHEN NVL(A.COPR_RQPR_ID, '1') != '1' THEN 1 ELSE 0 END) AS RQST_CNT, -- 요청건수
SUM(CASE_WHEN NVL(C.SRTR_EMPY_NO, '1') != '1' THEN 1 ELSE 0 END) AS SPRT_CNT, -- 지원건수
FROM CL_COPR_RQST X A
, CL_COPR_PROS_DPRT_X B
, CM_DPRT_M D
, CM_USR_M E
, CM_DPRT_M F
, CM_EMP_M G
, CM_DPRT_M D1
, CM_DPRT_M D2
, CM_DPRT_M D3
WHERE A.COPR_RQST_SEQ = B.COPR_RQST_SEQ(+)
AND B.COPR_RQST_SEQ = C.COPR_RQST_SEQ(+)
AND B.PROS_DPRT_SEQ = C.PROS_DPRT_SEQ(+)
AND A.COPR_RRQST_DPRT_CD = D.DPRT_CD(+)
AND A.COPR_RQPR_ID = E.USR_ID(+)
AND B.PROS_DPRT_CD = F.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND A.COPR_RQST_DPRT_CD = D1.DPRT_CD(+)
AND D1.UPER_DPRT_CD = D2.DPRT_CD(+)
AND D2.UPER_DPRT_CD = D3.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND A.COPR_RQST_DPRT_CD IN (SELECT V.DPRT_CD
FROM CM_DPRT_M V
START WITH V.DPRT_CD IN ( SELECT REGEXP_SUBSTR('50000174', '[^,]+',1, LEVEL COL
FROM DUAL CONNECT BY LEVEL <= REGEXP_COUNT('50000174', ',')+1)
CONNECT BY PRIOR V.DPRT_CD = V.UPER_DPRT_CD
)
GROUP BY D2.DPRT_NM, D2.DPRT_CD, D2.DPRT_SRTN_SQNC
-------------------------------------------------------
이걸 쪼개서
SELECT
D2.DPRT_NM
D2.DPRT_CD
D2.DPRT_SRTN_SQNC
SUM(CASE_WHEN NVL(A.COPR_RQPR_ID, '1') != '1' THEN 1 ELSE 0 END) AS RQST_CNT, -- 요청건수
SUM('') AS SPRT_CNT, -- 지원건수
FROM CL_COPR_RQST X A
, CL_COPR_PROS_DPRT_X B
, CM_DPRT_M D
, CM_USR_M E
, CM_DPRT_M F
, CM_EMP_M G
, CM_DPRT_M D1
, CM_DPRT_M D2
, CM_DPRT_M D3
WHERE A.COPR_RQST_SEQ = B.COPR_RQST_SEQ(+)
AND B.COPR_RQST_SEQ = C.COPR_RQST_SEQ(+)
AND B.PROS_DPRT_SEQ = C.PROS_DPRT_SEQ(+)
AND A.COPR_RRQST_DPRT_CD = D.DPRT_CD(+)
AND A.COPR_RQPR_ID = E.USR_ID(+)
AND B.PROS_DPRT_CD = F.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND A.COPR_RQST_DPRT_CD = D1.DPRT_CD(+)
AND D1.UPER_DPRT_CD = D2.DPRT_CD(+)
AND D2.UPER_DPRT_CD = D3.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND A.COPR_RQST_DPRT_CD IN (SELECT V.DPRT_CD
FROM CM_DPRT_M V
START WITH V.DPRT_CD IN ( SELECT REGEXP_SUBSTR('50000174', '[^,]+',1, LEVEL COL
FROM DUAL CONNECT BY LEVEL <= REGEXP_COUNT('50000174', ',')+1)
CONNECT BY PRIOR V.DPRT_CD = V.UPER_DPRT_CD
)
GROUP BY D2.DPRT_NM, D2.DPRT_CD, D2.DPRT_SRTN_SQNC
UNION
SELECT
D2.DPRT_NM
D2.DPRT_CD
D2.DPRT_SRTN_SQNC
SUM('') AS RQST_CNT, -- 요청건수
SUM(CASE_WHEN NVL(C.SRTR_EMPY_NO, '1') != '1' THEN 1 ELSE 0 END) AS SPRT_CNT, -- 지원건수
FROM CL_COPR_RQST X A
, CL_COPR_PROS_DPRT_X B
, CM_DPRT_M D
, CM_USR_M E
, CM_DPRT_M F
, CM_EMP_M G
, CM_DPRT_M D1
, CM_DPRT_M D2
, CM_DPRT_M D3
WHERE A.COPR_RQST_SEQ = B.COPR_RQST_SEQ(+)
AND B.COPR_RQST_SEQ = C.COPR_RQST_SEQ(+)
AND B.PROS_DPRT_SEQ = C.PROS_DPRT_SEQ(+)
AND A.COPR_RRQST_DPRT_CD = D.DPRT_CD(+)
AND A.COPR_RQPR_ID = E.USR_ID(+)
AND B.PROS_DPRT_CD = F.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND B.PROS_DPRT_CD = D1.DPRT_CD(+) -- 이부분 다름.
AND D1.UPER_DPRT_CD = D2.DPRT_CD(+)
AND D2.UPER_DPRT_CD = D3.DPRT_CD(+)
AND C.SRTR_EMPY_NO = G.EMPY_NO(+)
AND B.PROS_DPRT_CD IN (SELECT V.DPRT_CD -- 이부분 다름
FROM CM_DPRT_M V
START WITH V.DPRT_CD IN ( SELECT REGEXP_SUBSTR('50000174', '[^,]+',1, LEVEL COL
FROM DUAL CONNECT BY LEVEL <= REGEXP_COUNT('50000174', ',')+1)
CONNECT BY PRIOR V.DPRT_CD = V.UPER_DPRT_CD
)
AND B.COPR_PRGR_SCD = '4' -- 이부분 다름
GROUP BY D2.DPRT_NM, D2.DPRT_CD, D2.DPRT_SRTN_SQNC
------------------------------------------
이상입니다.
WITH d0 AS ( SELECT DISTINCT dprt_cd, uper_dprt_cd FROM cm_dprt_m v START WITH dprt_cd IN (SELECT REGEXP_SUBSTR(v_dprt_cd, '[^,]+', 1, LEVEL) COL FROM (SELECT '50000174' v_dprt_cd FROM dual) CONNECT BY LEVEL <= REGEXP_COUNT(v_dprt_cd, ',') + 1 ) CONNECT BY PRIOR dprt_cd = uper_dprt_cd ) SELECT dprt_nm , dprt_cd , dprt_srtn_sqnc , SUM(rqst_cnt) rqst_cnt , SUM(sprt_cnt) sprt_cnt FROM (SELECT d2.dprt_nm , d2.dprt_cd , d2.dprt_srtn_sqnc , COUNT(*) rqst_cnt , 0 sprt_cnt FROM cl_copr_rqst_x a , d0 , cm_dprt_m d2 WHERE a.copr_rqst_dprt_cd = d0.dprt_cd AND d0.uper_dprt_cd = d2.dprt_cd(+) AND a.copr_rqpr_id != '1' GROUP BY d2.dprt_nm, d2.dprt_cd, d2.dprt_srtn_sqnc UNION ALL SELECT d2.dprt_nm , d2.dprt_cd , d2.dprt_srtn_sqnc , 0 rqst_cnt , COUNT(*) sprt_cnt FROM cl_copr_pros_dprt_x b , ??????????????????? c , d0 , cm_dprt_m d2 WHERE b.copr_rqst_seq = c.copr_rqst_seq(+) AND b.pros_dprt_seq = c.pros_dprt_seq(+) AND b.pros_dprt_cd = d0.dprt_cd AND d0.uper_dprt_cd = d2.dprt_cd(+) AND b.copr_prgr_scd = '4' AND c.srtr_empy_no != '1' GROUP BY d2.dprt_nm, d2.dprt_cd, d2.dprt_srtn_sqnc ) GROUP BY dprt_nm, dprt_cd, dprt_srtn_sqnc ;