LEAD

functionsupportedCore SQL functions

docs.snowflake.com ↗

Window function syntax and usage

Accesses data in a subsequent row in the same result set without having to join the table to itself.

Syntax

supportedpartialnot supportednot scored

LEAD ( <expr> [ , <offset> , <default> ] ) [ { IGNORE | RESPECT } NULLS ]
  OVER ( [ PARTITION BY <expr1> ] ORDER BY <expr2> [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] )

Parameters

NameRequiredDescription
exprrequiredThe string expression to be returned.
offsetrequiredThe number of rows forward from the current row from which to obtain a value. For example, an offset of 2 returns the expr value with an interval of 2 rows. Note that setting a negative offset has the same effect as using the LAG function. Default is 1. If IGNORE NULLS is specified, maximum is 1,000,000.
defaultrequiredThe expression to return when the offset goes out of the bounds of the window. Supports any expression whose type is compatible with expr. Default is NULL.
{ IGNORE | RESPECT } NULLSrequiredWhether to ignore or respect NULL values when an expr contains NULL values: IGNORE NULLS excludes any row whose expression evaluates to NULL when offset rows are counted. RESPECT NULLS includes any row whose expression evaluates to NULL when offset rows are counted. Default: RESPECT NULLS

Usage notes

See also

Referenced by