안녕하세요... 기초가 너무 부족해서 지금 너무 힘드네요...ㅠㅠ 도와주세요...ㅠㅠ WITH T AS( SELECT '100-01-01' HIS_SEQ, NULL PA_HIS_SEQ FROM dual UNION ALL SELECT '100-01-02','100-01-01' FROM dual UNION ALL SELECT '100-01-03','100-01-02' FROM dual UNION ALL SELECT '100-01-04','100-01-03' FROM dual UNION ALL SELECT '100-01-05','100-01-04' FROM dual UNION ALL SELECT '100-01-06','100-01-05' FROM dual)SELECT LEVEL LV ,HIS_SEQ ,PA_HIS_SEQ ,SUBSTR(SYS_CONNECT_BY_PATH(HIS_SEQ, ','), 2) S_NAME FROM T START WITH PA_HIS_SEQ IS NULLCONNECT BY PRIOR HIS_SEQ = PA_HIS_SEQORDER BY HIS_SEQ
여기서 PIVOT을 사용하여
SELECT
MAX(A)A
,MAX(B)B
,MAX(C)C
,MAX(D)D
,MAX(E)E
,MAX(F)F
,MAX(S_NAME)S_NAME
FROM
(
WITH T AS
(
SELECT '100-01-01' HIS_SEQ, NULL PA_HIS_SEQ FROM dual
UNION ALL SELECT '100-01-02','100-01-01' FROM dual
UNION ALL SELECT '100-01-03','100-01-02' FROM dual
UNION ALL SELECT '100-01-04','100-01-03' FROM dual
UNION ALL SELECT '100-01-05','100-01-04' FROM dual
UNION ALL SELECT '100-01-06','100-01-05' FROM dual
)
SELECT
LEVEL LV
,HIS_SEQ
,PA_HIS_SEQ
,SUBSTR(SYS_CONNECT_BY_PATH(HIS_SEQ, ','), 2) S_NAME
FROM T
START WITH PA_HIS_SEQ IS NULL
CONNECT BY PRIOR HIS_SEQ = PA_HIS_SEQ
ORDER BY HIS_SEQ
)
PIVOT
(
MAX(HIS_SEQ)
FOR LV IN
(
1 AS A,2 AS B,3 AS C,4 AS D,5 AS E,6 AS F
)
)
파일 첨부와 같이 결과를 나타낼수 있는데 여기서
PIVOT
(
MAX(HIS_SEQ)
FOR LV IN
(
1 AS A,2 AS B,3 AS C,4 AS D,5 AS E,6 AS F
)
)
IN에 들어가는 컬럼들을 동적으로 나타내고 싶습니다.
HIS_SEQ ROW가 추가가 되면 동적으로 컬럼도 늘어나는 식으로 나타내고 싶은데 어떻게해야 될까요..???ㅠㅠ
PIVOT 말고 다른 방법도 있으면 알려주시면 감사드리겠습니다....ㅠㅠ
지금 이걸로 몇시간째 헤매고 있네요........ㅠㅠㅠ