LEAD
functionsupportedCore SQL functionsAccesses 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
| Name | Required | Description |
|---|---|---|
expr | required | The string expression to be returned. |
offset | required | The 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. |
default | required | The 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 } NULLS | required | Whether 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
- The PARTITION BY clause partitions the result set produced by the FROM clause into partitions to which the function is applied. For more information, see Window function syntax and usage.
- The ORDER BY clause orders the data within each partition.