년월별 집계 Data 쿼리 방법 문의드립니다.
대략적인 Raw Data는 아래와 같으며, Part No, Supplier, type, Currency 별로
PRICE 값이 년월(YYYYMM)으로 열의 값으로 표시되어야 됩니다.
꼭 반영되어야 하는 고려사항은 아래 두개고요, 여기 Q/A에 올라온 내용을 참조해서
쿼리를 만들어봤는데 정말 어렵네요...ㅠ 고수님들 부탁 드리겠습니다.
<고려사항>1) 월 중에 PRICE값이 한번이상 변경 시 해당월의 값은 마지막 일자의 PRICE 값을 표시
2) END_DATE 값이 '29991231'인 경우 현재 유효한 PRICE임
<raw data>
|
PART_NO |
SUPPLIER |
TYPE |
CURRENCY |
PRICE |
START_DATE |
END_DATE |
1 |
ABC |
S1 |
1 |
KRW |
0.0608 |
20130501 |
20130630 |
2 |
ABC |
S1 |
1 |
KRW |
0.0596 |
20130701 |
29991231 |
3 |
ABC |
S1 |
2 |
KRW |
0.0608 |
20130304 |
20130630 |
4 |
ABC |
S1 |
2 |
KRW |
0.0596 |
20130701 |
29991231 |
5 |
ABC |
S1 |
1 |
USD |
0.0097 |
20130304 |
20130430 |
6 |
DEF |
S2 |
2 |
KRW |
0.0005 |
20121204 |
20130330 |
7 |
DEF |
S2 |
2 |
KRW |
0.0004 |
20130401 |
20130420 |
8 |
DEF |
S2 |
2 |
KRW |
0.0003 |
20130421 |
29991231 |
WITH t AS
SELECT 'ABC' part_no ,'S1' supplier ,'1' TYPE ,'KRW' currency ,0.0608 price ,'20130501' start_date ,'20130630' end_date FROM dual
UNION ALL
SELECT 'ABC' ,'S1' ,'1' ,'KRW' ,0.0596 ,'20130701' ,'29991231' FROM dual
UNION
SELECT 'ABC' ,'S1' ,'2' ,'KRW' ,0.0608 ,'20130304' ,'20130630' FROM dual
UNION ALL
SELECT 'ABC' ,'S1' ,'2' ,'KRW' ,0.0596 ,'20130701' ,'29991231' FROM dual
UNION
SELECT 'ABC' ,'S1' ,'1' ,'USD' ,0.0097 ,'20130304' ,'20130430' FROM dual
UNION ALL
SELECT 'DEF' ,'S2' ,'2' ,'KRW' ,0.0005 ,'20121204' ,'20130330' FROM dual
UNION ALL
SELECT 'DEF' ,'S2' ,'2' ,'KRW' ,0.0004 ,'20130401' ,'29991231' FROM dual
UNION ALL
SELECT 'DEF' ,'S2' ,'1' i ,'USD' ,0.0003 ,'20130304' ,'20130430' FROM dual
<집계 data>
No. |
Part No |
Supplier |
type |
Currency |
201212 |
201301 |
201302 |
201303 |
201304 |
201305 |
201306 |
201307 |
201308 |
201309 |
201310 |
201311 |
201312 |
1 |
ABC |
S1 |
1 |
KRW |
|
|
|
|
|
0.0608 |
0.0608 |
0.0596 |
0.0596 |
0.0596 |
0.0596 |
0.0596 |
|
2 |
ABC |
S1 |
2 |
KRW |
|
|
|
0.0608 |
0.0608 |
0.0608 |
0.0608 |
0.0596 |
0.0596 |
0.0596 |
0.0596 |
0.0596 |
|
3 |
ABC |
S1 |
1 |
USD |
|
|
|
0.0097 |
0.0097 |
|
|
|
|
|
|
|
|
4 |
DEF |
S2 |
2 |
KRW |
0.0005 |
0.0005 |
0.0005 |
0.0005 |
0.0003 |
0.0003 |
0.0003 |
0.0003 |
0.0003 |
0.0003 |
0.0003 |
0.0003 |
|