Skip to main content

LAST_VALUE (SQL)

A window function that assigns the last value of the field column within the window frame to each of the other values in that column.

Synopsis

LAST_VALUE(field)

Description

LAST_VALUE uses the value of the field column from the last row to assign to all rows in the specific window frame. LAST_VALUE supports the ROWS clause.

Note that the NULL collates before all values, so if the value of field in the last row is NULL, all of the rows in the window will be NULL.

Arguments

field

A column that specifies which value to assign to all rows in that window frame.

Examples

The following example returns the last value of the Country column within each city:

SELECT LAST_VALUE(Country) OVER (PARTITION BY City)

See Also

FeedbackOpens in a new tab