SELECT TA.PM_CD,
TA.CUR_JEGO, ISNULL(SA.WT, 0) WT
FROM APG004T TA, (SELECT T1.PM_CD AS PM_CD, SUM(T1.WT) AS WT
FROM APG002S T1, APG002T T2
WHERE T1.FACT_CD = T2.FACT_CD
AND T1.PROP_DT = T2.DT1 AND T1.PROP_SEQ = T2.SEQ
AND T1.FACT_CD='BA' AND T2.DT2 BETWEEN '20081217' AND '20081219'
AND T1.PACK_TYPE='KG' AND T1.DELV_WT = 0
GROUP BY T1.PM_CD) SA
WHERE TA.PM_CD *= SA.PM_CD AND TA.FACT_CD='BA' AND TA.DT='20081217'
AND TA.PM_GUBN='20' AND TA.PACK_TYPE='KG'
이렇게 생긴 쿼리가 실행이 안되서 left join 문이 안먹어서
이런식의 쿼리를 만들었는데 여전히 실행이 되지 않습니다...
SELECT APG004T.PM_CD,
MAX(APG004T.CUR_JEGO),
SUM(ISNULL(APG002S.WT,0)) WT
FROM APG004T, APG002T, APG002S
WHERE APG004T.FACT_CD='BA' AND APG004T.DT='20081217'
AND APG004T.PM_GUBN='20' AND APG004T.PACK_TYPE='KG'
AND APG002S.PACK_TYPE='KG' AND APG002S.DELV_WT = 0
AND APG002S.FACT_CD = APG002T.FACT_CD
AND APG002S.PROP_DT = APG002T.DT1
AND APG002S.PROP_SEQ = APG002T.SEQ
AND APG002T.DT2 BETWEEN '20081217' AND '20081219'
AND APG004T.PM_CD *= APG002S.PM_CD ==> '=' 이렇게 바꾸면 일부만 나오고요
GROUP BY APG004T.PM_CD
해서 이런식으로 바꿨더니 역시 실행이 되질 않습니다.
T-SQL로 돌아갈 수 있게 하려면 어떻게 바꿔야 좋을까요??
감사합니다~
|