피벗이 뭐죠?? 0 0 1,887

by 송미진 [2007.07.26 10:14:49]


안녕하세요....초짜입니다.ㅜㅜ

아래의 쿼리문은 원하는 결과를 뽑기 위해 작성한 쿼리문입니다.

그 결과문은 아래에 나와있구요.

그런데 그 ■결과를 ■결과물바꾸기로 바꾸어 출력하고 싶은데요...

여기저기 뒤지다 피벗을 이용한다는걸 알게 되었습니다.

그런데 그 방법을 모르겠어요.

COL 어쩌꼬를 쭈욱 만들고 이렇게 저렇게 해보니 에러만나고..정말 난갑합니다.

도와 주세요...ㅠㅠ

그리고 한가지 더요.....

■ 최종결과물처럼 각단계별로 총합을 구해서 볼 수도 있나요?

 

아래의 내용을 보기 어려우시다면 첨부파일을 봐주세요..부탁드립니다...

 

///////////////////////////////////////////////////////////////////////////

■ 쿼리문
SELECT  A.HIGHDEPTNAME, A.deptno,A.DEPTNAME, count(A.deptno) deptno_CNT, A.STATUS
FROM (SELECT B.DEPTNO DEPTNO, B.DEPTNAME, B.HIGHDEPTNAME, B.INDEPTCODE INDEPTCODE,
    A.PJTNM PJTNM, A.PJT_LEADER, D.TITLENAME, A.WHOLERES_USER, A.PJT_CLASS,
       NVL(TO_CHAR(A.PLAN_DT1,'MM/DD'),'-') PLAN_DT1,
    NVL(TO_CHAR(A.PLAN_DT2,'MM/DD'),'-') PLAN_DT2,
    NVL(TO_CHAR(A.PLAN_DT3,'MM/DD'),'-') PLAN_DT3,
    NVL(TO_CHAR(A.PLAN_DT4,'MM/DD'),'-') PLAN_DT4,
    NVL(TO_CHAR(A.PLAN_DT6,'MM/DD'),'-') PLAN_DT6,
    NVL(TO_CHAR(A.END_DT1 ,'MM/DD'),'-') END_DT1,
    NVL(TO_CHAR(A.END_DT2 ,'MM/DD'),'-') END_DT2,
    NVL(TO_CHAR(A.END_DT3 ,'MM/DD'),'-') END_DT3,
    NVL(TO_CHAR(A.END_DT4 ,'MM/DD'),'-') END_DT4,
    NVL(TO_CHAR(A.END_DT6 ,'MM/DD'),'-') END_DT6,
    A.STATUS, c.titlecode,
    DECODE(A.STATUS, '완료','완료', DECODE(SIGN(DELAY_NUM),1,'지연','정상')) DELAY_STATUS
   FROM  (SELECT * FROM VW_CTO_6SIGMA_PJT_MASTER_NEW 
     WHERE VC_YEAR = TO_CHAR(SYSDATE,'YYYY')  
       OR (VC_YEAR = TO_CHAR(ADD_MONTHS(SYSDATE,-12),'YYYY') AND  
       (   STATUS NOT IN ('잠재','선정','완료')  
       OR TO_CHAR(PLAN_DT6, 'YYYY') = TO_CHAR(SYSDATE,'YYYY') AND STATUS NOT IN ('완료')  
       OR TO_CHAR(PLAN_DT6, 'YYYY') = TO_CHAR(SYSDATE,'YYYY') AND TO_CHAR(END_DT6, 'YYYY') = TO_CHAR(SYSDATE,'YYYY')  
        )  
    )  
   )A, CTO_DEPT B, CTO_USER C, CTO_TITLE D
   WHERE A.DEPTNO = B.DEPTNO(+) AND B.DEPTNO NOT IN (SELECT DEPTNO FROM CTO_DEPTNOT)
  AND A.EMPNO = C.EMPNO(+) AND C.TITLECODE = D.TITLECODE(+)
  AND A.PJT_CLASS IN ('MEGA','GROUP','중점') ) A, CTO_USER B, CTO_TITLE C
WHERE A.WHOLERES_USER = B.SSN(+) AND B.TITLECODE = C.TITLECODE(+)
  AND SUBSTR(A.INDEPTCODE,1,10)='0102010602'
GROUP BY A.HIGHDEPTNAME,A.DEPTNO,A.DEPTNAME, A.STATUS
ORDER BY A.HIGHDEPTNAME,A.DEPTNO

■ 결과
=========================================================================================
HIGHDEPTNAME   DEPTNO         DEPTNAME         DEPTNO_CNT STATUS
=========================================================================================
전략실           C10S0969         개발팀                1         2단계완료
전략실           C10S0969         개발팀                1         3단계완료
혁신팀           C10S0961         6/T그룹                1            3단계완료
혁신팀           C10S0971         VIP                2         1단계완료
혁신팀           C10S0971         VIP                1         2단계완료
혁신팀           C10S0971         VIP                2         3단계완료
혁신팀           C10S0972         기구                3         3단계완료
혁신팀           C10S0973         프로                2         3단계완료
혁신팀           C10S0973         프로                1         선정
혁신팀           C10S0979         회로                3         3단계완료
=========================================================================================

■ 결과물바꾸기
=============================================================================================================================
HIGHDEPTNAME   DEPTNO         DEPTNAME         1단계완료    2단계완료    3단계완료    4단계완료    5단계완료
=============================================================================================================================
전략실      C10S0969         개발팀                 -            1            1            -            - 
혁신팀           C10S0961         6/T그룹                 -            -            1            -            -
혁신팀           C10S0971         VIP                 2            1            3            -            -
혁신팀           C10S0972         기구                 -            -            3            -            -
혁신팀           C10S0973         프로                 -            -            2            -            -
혁신팀           C10S0979         회로              -            -            3            -            -
=============================================================================================================================

■ 최종결과물
=============================================================================================================================
HIGHDEPTNAME   DEPTNO         DEPTNAME         1단계완료    2단계완료    3단계완료    4단계완료    5단계완료
=============================================================================================================================
-          -          -                       2            2            13           -            -
전략실      C10S0969         개발팀                 -            1            1            -            - 
혁신팀           C10S0961         6/T그룹                 -            -            1            -            -
혁신팀           C10S0971         VIP                 2            1            3            -            -
혁신팀           C10S0972         기구                 -            -            3            -            -
혁신팀           C10S0973         프로                 -            -            2            -            -
혁신팀           C10S0979         회로              -            -            3            -            -
=============================================================================================================================

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입