with data
as ( select 1 a, 6 b, 3 c, 2 d, 5 e from dual union all
select 2 a, 4 b, 5 c, 8 d, 9 e from dual union all
select 3 a, 5 b, 7 c, 10 d, 13 e from dual
)
select *
from data
아래와 같은 샘플 데이터가 있을떄, 1번 row에 대해서만
a 컬럼 밑에는 a-0
b 컬럼 밑에는 b-a
c 컬럼 밑에는 c-b
d 컬럼 밑에는 d-c
e 컬럼 밑에는 e-d
구하고 싶은데, 쿼리 부탁드립니다
[샘플 데이터]
a b c d e <-- 컬럼
1 6 3 2 5 <-- row1
2 4 5 8 9 <-- row2
3 5 7 10 13 <-- row3
[결과]
a b c d e <-- 컬럼
1 6 3 2 5 <-- row1
1 5 -3 -1 3 <-- 결과 컬럼
2 4 5 8 9 <-- row2
3 5 7 10 13 <-- row3
WITH data AS ( SELECT 1 order_seq, 1 a, 6 b, 3 c, 2 d, 5 e FROM dual UNION ALL SELECT 2, 2, 4, 5, 8, 9 FROM dual UNION ALL SELECT 3, 3, 5, 7, 10, 13 FROM dual ) SELECT rn , lv , a , DECODE(lv, 1, b, b - a) b , DECODE(lv, 1, c, c - b) c , DECODE(lv, 1, d, d - c) d , DECODE(lv, 1, e, e - d) e FROM (SELECT ROW_NUMBER() OVER(ORDER BY order_seq) rn , a, b, c, d, e FROM data ) , (SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 2) WHERE lv <= DECODE(rn, 1, 2, 1) ORDER BY rn, lv ;