업체명에 따른 주수별 합계를 구하는 쿼리입니다..
아래 쿼리문을 실행하면..
sum 함수가 잘 못 되어 잇는거 같긴 한데 확실히 어떻게 잘못 쓴건지를 모르겟습니다..
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT DECODE(CMP_NAME,NULL,'합계',CMP_NAME)AS 업체명,
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='1')AS "1주",
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='2')AS "2주",
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='3')AS "3주",,
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='4')AS "4주",,
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='5')AS "5주",,
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='6')AS "6주",,
--가로합계
(SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='1')+
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='2')+
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='3')+
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='4')+
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='5')+
SUM(SELECT TO_CHAR(PUT_START_DAY,'W') FROM INSA_EMP_PJT WHERE TO_CHAR(PUT_START_DAY,'W')='6'))AS "TOT"
FROM
INSA_COMPANY T1,
INSA T2,
INSA_EMP_PJT T3
WHERE 1=1
AND ((T3.PUT_START_DAY >=TO_DATE(:IN_YYYY||'0101','YYYYMMDD')AND T3.PUT_START_DAY <TO_DATE(:IN_YYYY||'1231','YYYYMMDD')+1)
OR
(T3.PUT_END_DAY >=TO_DATE(:IN_YYYY||'0101','YYYYMMDD')AND T3.PUT_END_DAY <TO_DATE(:IN_YYYY||'1231','YYYYMMDD')+1))
AND TW.SABUN=T3.SABUN
AND T1.CMP_REG_NO=T2.CMP_REG_NO
GROUP BY ROLLUP(T1.CMP_NAME)
ORDER BY T1.CMP_NAME;
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------