lag(), lead() 함수

yshjft·2024년 2월 11일
0

Postgresql

목록 보기
3/11

lag()

포맷

lag(value any [, offset integer [, default any ]])

실제 사용

SELECT z_myid, lag(z_myid) OVER (ORDER BY z_myid) BEFORE
FROM list

설명

  • returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead return default. Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null.

  • 특정 컬럼의 이전 행의 값을 구하는 window function

lead()

포맷

lead(value any [, offset integer [, default any ]])

실제 사용

SELECT z_myid, lead(z_myid) OVER (ORDER BY z_myid) NEXT
FROM list

설명

  • returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead return default. Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null

  • 특정 컬럼의 다음 행의 값을 구하는 window function

참고 자료

profile
꾸준히 나아가자 🐢

0개의 댓글