LEAD(필드명) OVER (PARTITION BY 그룹필드명 ORDER BY 정렬필드 명)
★ ORDER BY 필수
SELECT TRAIN_NO, RUN_ORDR, STATION_NM,
NVL(LEAD(STATION_NM) OVER(PARTITION BY TRAIN_NO ORDER BY RUN_ORDR),' ') NEXT_STATION
FROM TB_TRAIN_TM;
LAG(필드명) OVER (PARTITION BY 그룹필드명 ORDER BY 정렬필드 명)
SELECT TRAIN_NO, RUN_ORDR, STATION_NM,
NVL(LAG(STATION_NM) OVER(PARTITION BY TRAIN_NO ORDER BY RUN_ORDR),' ') PREV_STATION
FROM TB_TRAIN_TM;
'스터디 > Oracle' 카테고리의 다른 글
[Oracle / 오라클] 집합 연산자 UNION, UNION ALL, MINUS, INTERSECT (0) | 2023.06.19 |
---|---|
[Oracle / 오라클] group by, count, sum (0) | 2023.06.19 |
[Oracle/오라클] FIRST_VALUE() 필드의 첫번째 값, LAST_VALUE() 마지막 값 구하기 (0) | 2021.10.19 |
[오라클/Oracle] INSTER, SUBSTR, REPLACE (0) | 2021.09.18 |
[Oracle/오라클] 다중 LIKE 조건 REGEXP_LIKE (0) | 2021.07.17 |