728x90

[참고]http://develop.sunshiny.co.kr/485

WITH T AS
(
SELECT 1 A FROM DUAL UNION ALL
SELECT 2 FROM DUAL UNION ALL
SELECT 3 FROM DUAL UNION ALL
SELECT 4 FROM DUAL UNION ALL
SELECT 5 FROM DUAL
)
SELECT A,
LAG(A, 1, 123) OVER(ORDER BY A) PREV_VALUE,
LEAD(A, 1, 123) OVER(ORDER BY A) NEXT_VALUE
FROM T;

[설명]

## LAG(), LEAD() 함수 사용시 필수입력 : OVER(ORDER BY )

-- LAG(A, B, C) A:대상로우, B:가져올위치(대상로우 이전값, default:1), C:기본으로 채울값(default: NULL값)
-- LEAD(A, B, C) A:대상로우, B:가져올위치(대상로우 다음값, default:1), C:기본으로 채울값
(default: NULL값)

728x90

+ Recent posts