반응형
가로데이터를 세로로 만들어야 할때,
with main_T as (
SELECT '1' A1 , '2' A2 , '3' A3 , '4' A4,'5' A5, '6' A6 , '7' A7 FROM DUAL
), copy_t as (
SELECT 'A' gubun FROM dual
UNION ALL SELECT 'B' FROM dual
UNION ALL SELECT 'C' FROM dual
UNION ALL SELECT 'D' FROM dual
UNION ALL SELECT 'E' FROM dual
UNION ALL SELECT 'F' FROM dual
UNION ALL SELECT 'G' FROM dual
)SELECT
c.gubun
, CASE WHEN c.gubun = 'A' THEN m.a1
WHEN c.gubun = 'B' THEN m.a2
WHEN c.gubun = 'C' THEN m.a3
WHEN c.gubun = 'D' THEN m.a4
WHEN c.gubun = 'E' THEN m.a5
WHEN c.gubun = 'F' THEN m.a6
WHEN c.gubun = 'G' THEN m.a7
END amt
FROM main_t m , copy_t c
ORDER BY c.gubun
;
반응형
'DataBase > oracle' 카테고리의 다른 글
Oracle standard... table column comment, table comment (0) | 2011.11.03 |
---|---|
oracle 10g 이상 WM_CONCAT (여러 row 를 한컬럼에) (0) | 2011.08.30 |
Oracle - DB link (0) | 2011.04.14 |
oracle table space create and user creation (0) | 2011.04.12 |
Oracle User Creation And Authority[유저생성 및 권한] (0) | 2011.02.22 |