1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | -- (1:다:다) 관계는 자칫 잘못 조인 하면 카티션곱이 발생됩니다. -- (다)의 집합을 우선 (1)로 만든 후, (1:1:1) 로 조인하시는게 좋습니다. SELECT a.orgzno , a.etc , a.empno , NVL(b.amt_1, 0) amt_1 , NVL(b.amt_2, 0) amt_2 , NVL(c.crs_1, 0) crs_1 , NVL(c.crs_2, 0) crs_2 , NVL(c.crs_3, 0) crs_3 FROM ( SELECT o.orgzno , o.etc , e.empno FROM emp e , orgz o WHERE e.orgzno = o.orgzno ) a , ( SELECT empno , SUM ( CASE WHEN ym = '201312' THEN amt END ) amt_1 , SUM ( CASE WHEN ym < '201312' THEN amt END ) amt_2 FROM acrs GROUP BY empno ) b , ( SELECT empno , COUNT ( CASE WHEN crs = '과정1' THEN 1 END ) crs_1 , COUNT ( CASE WHEN crs = '과정2' THEN 1 END ) crs_2 , COUNT ( CASE WHEN crs = '과정3' THEN 1 END ) crs_3 FROM edct GROUP BY empno ) c WHERE a.empno = b.empno(+) AND a.empno = c.empno(+) AND NVL(b.empno, c.empno) IS NOT NULL ORDER BY a.orgzno, a.empno ; |