SELECT 1 AS LV, 'A' AS CODE1, 'B' AS CODE2, NULL AS RATE, 10 AS VAL FROM DUAL UNION ALL
SELECT 2 AS LV, 'B' AS CODE1, 'C' AS CODE2, 0.5 AS RATE, NULL AS VAL FROM DUAL UNION ALL
SELECT 2 AS LV, 'B' AS CODE1, 'D' AS CODE2, 0.5 AS RATE, NULL AS VAL FROM DUAL UNION ALL
SELECT 3 AS LV, 'C' AS CODE1, 'F' AS CODE2, 1 AS RATE, NULL AS VAL FROM DUAL UNION ALL
SELECT 3 AS LV, 'D' AS CODE1, 'F' AS CODE2, 1 AS RATE, NULL AS VAL FROM DUAL
LV CODE1 CODE2 RATE VAL
---- ---------- ---------- -------- ------
1 A B 10
2 B C 0.5
2 B D 0.5
3 C F 1
3 D F 1
문의)
LV2부터 VAL을 구하고 싶습니다.
2번째 ROW의 VAL 값은 CODE2가 B인 VAL(10) * RATE(0.5)
3번째 ROW의 VAL 값은 CODE2가 B인 VAL(10) * RATE(0.5)
4번째 ROW의 VAL 값은 CODE2가 C인 VAL(2번째 ROW 계산값=5) * RATE(1)
5번째 ROW의 VAL 값은 CODE2가 D인 VAL(3번째 ROW 계산값=5) * RATE(1)
로
LV CODE1 CODE2 RATE VAL
---- ---------- ---------- -------- ------
1 A B 10
2 B C 0.5 5
2 B D 0.5 5
3 C F 1 5
3 D F 1 5
이렇게 SQL을 처리하고 싶어 문의드려요.
|