1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | WITH t AS ( SELECT 'Store01' AS cd, 10 AS won, 1 AS ymd FROM dual UNION ALL SELECT 'Store02' , 20, 2 FROM dual UNION ALL SELECT 'Store03' , 30, 3 FROM dual UNION ALL SELECT 'Store04' , 300, 4 FROM dual UNION ALL SELECT 'Store05' , 54, 5 FROM dual UNION ALL SELECT 'Store06' , 5, 6 FROM dual UNION ALL SELECT 'Store07' , 8, 7 FROM dual ) -- 2. Min(Decode(를 이용한 Pivot SELECT DECODE(lv, 1, 'Won' , 2, 'Ymd' ) gbn , MIN (DECODE(cd, 'Store01' , v)) Store01 , MIN (DECODE(cd, 'Store02' , v)) Store02 , MIN (DECODE(cd, 'Store03' , v)) Store03 , MIN (DECODE(cd, 'Store04' , v)) Store04 , MIN (DECODE(cd, 'Store05' , v)) Store05 , MIN (DECODE(cd, 'Store06' , v)) Store06 , MIN (DECODE(cd, 'Store07' , v)) Store07 FROM ( -- 1. Decode(lv 를 이용한 UnPivot SELECT lv , cd , DECODE(lv, 1, won, 2, ymd) v FROM t , ( SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 2) ) GROUP BY lv ORDER BY lv ; |