- Overview
- Data types
- Commands
- Functions
- Overview
- Aggregate
- Conditional expression
- Conversion
- Date and time
- Numeric
- String
- Semi-structured data
- Window
- System
On this page
lag, lead
Returns a value from a row before or after the current row in the window.
Syntax
lag( <expr> [, offset => <offset> ] [, default => <default_value> ] )
lead( <expr> [, offset => <offset> ] [, default => <default_value> ] )
Arguments
offset is an optional non-negative integer. The default is 1.
default is returned when the requested row is outside the window. The default is NULL.
Returns
Returns the same type as <expr>.
Examples
VALUES ('a'), ('b'), ('c')
WINDOW lag($0), lead($0);