PIVOT 검색해보세요. / 관련 강좌 http://www.gurubee.net/lecture/2214
표측과 표두를 바꿀 수 있는 함수입니다.
물론 요 함수 써도 자동으로 바뀌지 않습니다.
결국 하나 하나 항목을 기술하여 변경 해야 합니다.
WITH T (NAME,T1,T2,T3,T4,T6) AS
(
SELECT 'CODE1',11,77,7,5,5 FROM DUAL UNION ALL
SELECT 'CODE2',44,0,5,5,5 FROM DUAL UNION ALL
SELECT 'CODE3',11,2,3,2,4 FROM DUAL UNION ALL
SELECT 'CODE4',77,0,5,6,6 FROM DUAL UNION ALL
SELECT 'CODE5',55,1,7,8,8 FROM DUAL
)
SELECT *
FROM (
SELECT NAME, C1, CODE
FROM T
unpivot (CODE for C1 in (T1,T3,T6)))
pivot
(MIN(CODE) for NAME in ('CODE1','CODE2','CODE3','CODE4','CODE5'))
ORDER BY C1;
WITH TT(CODE, T1, T2, T3, T4, T6) AS( SELECT 'CODE1', 11,77,7,5,5 FROM DUAL UNION ALL SELECT 'CODE2', 44,0,5,5,5 FROM DUAL UNION ALL SELECT 'CODE3', 11,2,3,2,4 FROM DUAL UNION ALL SELECT 'CODE4', 77,0,5,6,6 FROM DUAL UNION ALL SELECT 'CODE5', 55,1,7,8,8 FROM DUAL ) SELECT 'T1' , MAX(DECODE(CODE,'CODE1',T1)) CODE1 , MAX(DECODE(CODE,'CODE2',T1)) CODE2 , MAX(DECODE(CODE,'CODE3',T1)) CODE3 , MAX(DECODE(CODE,'CODE4',T1)) CODE4 , MAX(DECODE(CODE,'CODE5',T1)) CODE5 FROM TT UNION ALL SELECT 'T3' , MAX(DECODE(CODE,'CODE1',T3)) CODE1 , MAX(DECODE(CODE,'CODE2',T3)) CODE2 , MAX(DECODE(CODE,'CODE3',T3)) CODE3 , MAX(DECODE(CODE,'CODE4',T3)) CODE4 , MAX(DECODE(CODE,'CODE5',T3)) CODE5 FROM TT UNION ALL SELECT 'T6' , MAX(DECODE(CODE,'CODE1',T6)) CODE1 , MAX(DECODE(CODE,'CODE2',T6)) CODE2 , MAX(DECODE(CODE,'CODE3',T6)) CODE3 , MAX(DECODE(CODE,'CODE4',T6)) CODE4 , MAX(DECODE(CODE,'CODE5',T6)) CODE5 FROM TT ;