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(")"),
  )
)
ParameterTypeRequiredDescription
exprEXPRESSIONYesExpression to get the first/last value of
over_clauseOVER CLAUSEYesOVER (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
Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19