LAST_VALUE() OVER ...
All functions > WINDOW FUNCTION > LAST_VALUE() OVER ...
Returns the last value in the window frame.
Syntax
Diagram(
Sequence(
Terminal("LAST_VALUE"),
Terminal("("),NonTerminal('expr'),Terminal(")"),
Terminal("OVER"),
Terminal("("),
NonTerminal("over_clause"),
Terminal(")"),
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | EXPRESSION | Yes | Expression to get the first/last value of |
over_clause | OVER CLAUSE | Yes | OVER (PARTITION BY ... ORDER BY ... [FRAME ...]) |
Notes
- Returns the value from the last row of the window frame
- ORDER BY determines which row is considered "last"
- PARTITION BY divides rows into independent groups
- Window frame controls which rows are considered
- Default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
- Note: With default frame, LAST_VALUE returns current row value
- Use ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING for true last value
- Returns same type as input expression
- NULL values are preserved