테이블 설명
PUB0900 코드 마스터
PUB0910 코드 디테일
기타 : 업무용 테이블
다음 쿼리에서 코드값을 가져오는 부분을 이해할 수 없습니다.(빨간색)
SELECT A.* FROM (
SELECT A.*, LEAD(STATUS, 1, 0) OVER(ORDER BY PR_NO, PO_REV DESC) AS BEFORE_STATUS FROM (
SELECT
A.PURREQ_NO,
A.PURREQ_TITLE,
A.PURREQ_ID,
(SELECT MAX(USER_NAME_K) FROM PUB0130V WHERE ACCT_ID = A.PUR_CHARGE) AS PUR_CHARGE,
(SELECT MAX(USER_NAME_K) FROM PUB0130V WHERE ACCT_ID = A.SUPT_CHARGE) AS SUPT_CHARGE,
(SELECT MAX(USER_NAME_K) FROM PUB0130V WHERE ACCT_ID = A.SPOT_CHARGE) AS SPOT_CHARGE,
A.REQ_DATE,
SUBSTR(A.DEL_START,0,4) || '-' || SUBSTR(A.DEL_START,5,2) || '-' || SUBSTR(A.DEL_START,7,2) || ' ~ '|| SUBSTR(A.DEL_END,0,4) || '-'
|| SUBSTR
(A.DEL_END,5,2) || '-' || SUBSTR(A.DEL_END,7,2) DEL_DATE ,
A.STATUS,
A.PURREQ_ID AS PURREQ_ID2,
( SELECT CODE_NAME_KOR
FROM PUB0910T
WHERE COMM_CODE_ID = (SELECT COMM_CODE_ID
FROM PUB0900T
WHERE COMM_CODE = 'PUR_PR_STATUS'
AND CODE = A.STATUS) ) AS STATUS2,
(SELECT COUNT(*) CNT FROM PUR1060T WHERE PURREQ_ID= A.PURREQ_ID ) ITEM_COUNT
, A.PR_NO, A.DEPT_CD, A.PO_REV
FROM PUR1050T A
,(
SELECT RFQ_ID, RFQ_STAT, DEPT_CD, PR_NO
FROM PUR3000T
WHERE RFQ_ID IN (
SELECT
MAX(RFQ_ID) RFQ_ID
FROM PUR3000T
WHERE (DEPT_CD, PR_NO) IN (
SELECT
DEPT_CD, PR_NO
FROM PUR1050T
WHERE 1=1
AND PR_NO IS NOT NULL
GROUP BY DEPT_CD, PR_NO
HAVING COUNT(*) > 1
)
GROUP BY DEPT_CD, PR_NO
)
) B
WHERE A.DEPT_CD = B.DEPT_CD
AND A.PR_NO = B.PR_NO
AND NOT EXISTS (
SELECT '1'
FROM PUR5000T C
WHERE C.RFQ_ID = B.RFQ_ID
)
) A
) A
WHERE 1=1
AND A.PO_REV > 0
ORDER BY PURREQ_NO DESC
;
근데 PUB0900에는 CODE란 필드가 없습니다. 에러가 나야 되는 건 아닌가요?
이렇게 되어야 하는데
( SELECT CODE_NAME_KOR
FROM PUB0910T
WHERE COMM_CODE_ID = (SELECT COMM_CODE_ID
FROM PUB0900T
WHERE COMM_CODE = 'PUR_PR_STATUS'
) AND CODE = A.STATUS) AS STATUS2,
결과는 똑같습니다.
왜 그런지 이유를 설명해 주실 분?
참고로 오라클 9i 입니다.