lag
analytic window function
Applies to: Databricks SQL Databricks Runtime
Returns the value of expr
from a preceding row within the partition.
Arguments
expr
: An expression of any type.offset
: An optional INTEGER literal specifying the offset.default
: An expression of the same type asexpr
.IGNORE NULLS
orRESPECT NULLS
: WhenIGNORE NULLS
is specified, anyexpr
value that is NULL is ignored. The default isRESPECT NULLS
.OVER clause: The clause describing the windowing. See: Window functions.
Returns
The result type matches expr
.
If offset
is positive the value originates from the row preceding the current row by offset
specified the ORDER BY in the OVER clause.
An offset of 0 uses the current row’s value.
A negative offset uses the value from a row following the current row.
If you do not specify offset
it defaults to 1, the immediately following row.
If there is no row at the specified offset within the partition, the specified default
is used.
The default
default is NULL
.
You must provide an ORDER BY clause.
This function is a synonym to lead(expr, -offset, default)
.