YYMM | GOODS | BASE_GUBUN | BASE_AMT | USE_GUBUN | USE_AMT | UTIL_GUBUN | AMT_UTIL |
201103 | D07 | 기본료 | 9240 | 장비임대료 | 4400 | 부가서비스 | 0 |
201103 | D44 | 기본료 | 0 | 장비임대료 | 0 | 부가서비스 | 1320 |
201103 | 406 | 기본료 | 14570 | 장비임대료 | 0 | 부가서비스 | 0 |
201104 | D07 | 기본료 | 9240 | 장비임대료 | 4400 | 부가서비스 | 0 |
YYMM | GOODS | GUBUN | AMT |
201103 | D07 | 기본료 | 9240 |
201103 | D44 | 기본료 | 0 |
201103 | 406 | 기본료 | 14570 |
201104 | D07 | 기본료 | 9240 |
201103 | D07 | 장비임대료 | 4400 |
201103 | D44 | 장비임대료 | 0 |
201103 | 406 | 장비임대료 | 0 |
201104 | D07 | 장비임대료 | 4400 |
201103 | D07 | 부가서비스 | 0 |
201103 | D44 | 부가서비스 | 1320 |
201103 | 406 | 부가서비스 | 0 |
201104 | D07 | 부가서비스 | 0 |
WITH t(yymm, goods, base_gubun, base_amt, use_gubun, use_amt, util_gubun, util_amt) AS ( SELECT '201103', 'D07', '기본료', 9240, '장비임대료', 4400, '부가서비스', 0 FROM dual UNION ALL SELECT '201103', 'D44', '기본료', 0, '장비임대료', 0, '부가서비스', 1320 FROM dual UNION ALL SELECT '201103', '406', '기본료', 14570, '장비임대료', 0, '부가서비스', 0 FROM dual UNION ALL SELECT '201104', 'D07', '기본료', 9240, '장비임대료', 4400, '부가서비스', 0 FROM dual ) SELECT * FROM t UNPIVOT ((gubun_nm, amt) FOR gubun_cd IN ( (base_gubun, base_amt) AS 1 , ( use_gubun, use_amt) AS 2 , (util_gubun, util_amt) AS 3 ) ) ORDER BY gubun_cd, yymm, goods ;
감사합니다 기본이 안돼있네요 제가 ㅠㅠ
마농님 쿼리를 찬찬히 돼새겨보니 여기서 제가 알고싶던 해결점을 찾았네요 감사드립니다 ~~ ^^
WITH T AS (
select 1012 as YR, 0 as "01", 0 as "02", 0 as "03", 0 as "04", 0 as "05", 0 as "06", 0 as "07", 0 as "08", 0 as "09", 0 as "10", 0 as "11", 0 as "12" from dual union all
select 2011 as YR, 0 as "01", 0 as "02", 0 as "03", 0 as "04", 0 as "05", 0 as "06", 0 as "07", 0 as "08", 0 as "09", 0 as "10", 0 as "11", 385 as "12" from dual union all
select 2012 as YR, 890 as "01", 645 as "02", 833 as "03", 416 as "04", 739 as "05", 360 as "06", 552 as "07", 828 as "08", 297 as "09", 223 as "10", 348 as "11", 228 as "12" from dual union all
select 2013 as YR, 1332 as "01", 680 as "02", 841 as "03", 385 as "04", 327 as "05", 781 as "06", 459 as "07", 829 as "08", 207 as "09", 135 as "10", 190 as "11", 466 as "12" from dual union all
select 2014 as YR, 261 as "01", 432 as "02", 895 as "03", 347 as "04", 396 as "05", 471 as "06", 529 as "07", 495 as "08", 159 as "09", 173 as "10", 167 as "11", 356 as "12" from dual union all
select 2015 as YR, 439 as "01", 266 as "02", 361 as "03", 0 as "04", 0 as "05", 0 as "06", 0 as "07", 0 as "08", 0 as "09", 0 as "10", 0 as "11", 0 as "12" from dual
)
select yr
, lv as mm
, decode(lv,1, "01"
,2, "02"
,3, "03"
,4, "04"
,5, "05"
,6, "06"
,7, "07"
,8, "08"
,9, "09"
,10,"10"
,11,"11"
,12,"12"
,0) as VAL
from (select level lv from dual connect by level<=12),t
where t.yr='2012'
;