시작일 종료일 코드 코드명 금액
20190220 20190225 0001 코드명1 100
20190226 20190228 0001 코드명1 200
20190301 20190302 0001 코드명1 300
위와 같은 데이터가 있을 경우 시작일과 종료일 사이에 데이터를 아래와 같이 일별로 한 로우로 뿌려주고 싶습니다.
시작일 종료일 코드 코드명 금액
20190220 20190225 0001 코드명1 100
20190221 20190225 0001 코드명1 100
20190222 20190225 0001 코드명1 100
20190223 20190225 0001 코드명1 100
20190224 20190225 0001 코드명1 100
20190225 20190225 0001 코드명1 100
20190226 20190228 0001 코드명1 200
20190227 20190228 0001 코드명1 200
20190228 20190228 0001 코드명1 200
20190301 20190302 0001 코드명1 300
20190302 20190302 0001 코드명1 300
쿼리로 어떻게 해야되는지 고수님들의 조언 부탁드립니다. (oracle)
with t as ( select '20190220' stdt, '20190225' todt, '0001' code, '코드명1' codenm, 100 amt from dual union all select '20190226' stdt, '20190228' todt, '0001' code, '코드명1' codenm, 200 amt from dual union all select '20190301' stdt, '20190302' todt, '0001' code, '코드명1' codenm, 300 amt from dual ) select to_char(to_date(stdt,'yyyymmdd') + lv - 1,'yyyymmdd') stdt, todt, code, codenm, amt from t , (select level lv from dual connect by level <= 365) -- 1년치가 max, 조정필요. where to_date(todt,'yyyymmdd') - to_date(stdt,'yyyymmdd') >= lv - 1 order by stdt
--까먹어서 연습용으로.. with t as ( select '20190220' stdt, '20190225' todt, '0001' code, '코드명1' codenm, 100 amt from dual union all select '20190226' stdt, '20190228' todt, '0001' code, '코드명1' codenm, 200 amt from dual union all select '20190301' stdt, '20190302' todt, '0001' code, '코드명1' codenm, 300 amt from dual ) , t1 (stdt, todt, code, codenm, amt) as ( select stdt, todt, code, codenm, amt from t union all select to_char(to_date(stdt,'yyyymmdd') + 1,'yyyymmdd') stdt, todt, code, codenm, amt from t1 where to_char(to_date(stdt,'yyyymmdd') + 1,'yyyymmdd') <= todt ) select * from t1 order by stdt