쿼리를 말로 표현하기 힘들어서 붙여넣기를 했습니다...간단히 요약하자면 2개의 ROW를 가진 테이블(각각,Y,N) 과 여러개의 ROW를가진 테이블(조인햇을시에 조인되는부분이없는테이블)과
아우터조인시 원테이블의 결과가 (Y,N) 에서 (N,N) 으로 결과가 나오게되는현상.... 원테이블만 SELECT 시에는 Y,N 결과값이 정상적으로나옴...
상단 결과의 ACCEPT_YN 의경우 ROW가 2라인이 생기는데 N,N이 결과로 나오고
아래 쿼리의 경우는 Y,N으로 나옵니다 실제 원테이블은 Y,N으로 등록되어있습니다
왜 다른지 이해가 가질 않습니다 ㅠㅠ 고수분들 도와주십시요.
---------------------------------------------
SELECT MST.AGREE_NO1 ,MST.AGREE_NO2 ,MST.AGREE_NO3 ,MST.AGREE_NO4
,MST.AGREE_CHASU ,MST.AGREE_SEQ ,MST.ACCEPT_YN
FROM SCM_AGREE_WONJAJAE MST
,(SELECT AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
,MAX(ACCEPT_YN) ACCEPT_YN
FROM (SELECT AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
,MAX(ACCEPT_YN) ACCEPT_YN
FROM SCM_WT_TOTAL_BALJU
WHERE DIVISION_CD = 'B'
GROUP BY AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
UNION ALL
SELECT AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
,MAX(ACCEPT_YN) ACCEPT_YN
FROM SCM_AGREE_WONJAJAE_BALJU
WHERE DIVISION_CD = 'B'
GROUP BY AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
)
GROUP BY AGREE_NO1,AGREE_NO2,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU,AGREE_SEQ
) SAIP
WHERE MST.DIVISION_CD = 'B'
AND MST.AGREE_NO1 = '1409'
AND MST.AGREE_NO2 = 'B'
AND MST.AGREE_NO3 = 'GM'
AND MST.AGREE_NO4 = '0001'
AND MST.AGREE_CHASU = '0'
AND MST.AGREE_NO1 = SAIP.AGREE_NO1 (+)
AND MST.AGREE_NO2 = SAIP.AGREE_NO2 (+)
AND MST.AGREE_NO3 = SAIP.AGREE_NO3 (+)
AND MST.AGREE_NO4 = SAIP.AGREE_NO4 (+)
AND MST.AGREE_CHASU = SAIP.AGREE_CHASU(+)
AND MST.AGREE_SEQ = SAIP.AGREE_SEQ (+) ;
-----------------------------------------------------------------------------
SELECT AGREE_NO1 ,AGREE_NO2 ,AGREE_NO3 ,AGREE_NO4
,AGREE_CHASU ,AGREE_SEQ ,ACCEPT_YN
FROM SCM_AGREE_WONJAJAE
WHERE DIVISION_CD = 'B'
AND AGREE_NO1 = '1409'
AND AGREE_NO2 = 'B'
AND AGREE_NO3 = 'GM'
AND AGREE_NO4 = '0001'
AND AGREE_CHASU = '0'
|