For AI agents: an index of this documentation is at https://developer.rippling.com/llms.txt. Public pages have a Markdown version at the same URL with .md added.

Skip to main content
index

LEAD() Function

Use with AI:Rippling AI ChatGPT Claude Cursor

Description​

Provides access to data from the next row in the result set without needing a self-join

Syntax​

LEAD(expression [, offset [, default]]) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression)

Parameters​

ParameterDescriptionData TypeRequired
expressionColumn or expression whose value is returned from a later rowAnyYes
offsetNumber of rows to look forward (defaults to 1)IntegerNo
defaultValue returned when the target row is outside the partitionAnyNo

Rewrite​

Use QUALIFY to filter on window expression results; do not use window functions in WHERE.

Notes​

  • Include an OVER (...) clause with ORDER BY (and optional PARTITION BY) when using this as a window function.

Example​

SELECT
id, LEAD(salary, 1) OVER (PARTITION BY department ORDER BY start_date) AS next_salary
FROM
rippling.employee.Employee;