FIRST_VALUE() OVER ...
All functions > WINDOW FUNCTION > FIRST_VALUE() OVER ...
Returns the first value in the window frame.
Syntax
Diagram(
Sequence(
Terminal("FIRST_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 first row of the window frame
- ORDER BY determines which row is considered "first"
- PARTITION BY divides rows into independent groups
- Window frame controls which rows are considered
- Default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
- Returns same type as input expression
- Useful for comparing current row with first row in partition
- NULL values are preserved