LAST_VALUE
Value function. Returns an expression evaluated at the last row of the window frame. If there are no rows in the frame, returns NULL
. For an overview of window functions in SingleStore DB, see Window Functions Guide.
Syntax
LAST_VALUE ( expression ) OVER ( [PARTITION BY (col | expr), ...] [ORDER BY (col | expr), ...] [frame_clause] )
Arguments
expression: any expression. This may be a column name, the result of another function, or a math operation.
Return Type
The result type of expression
Examples
create table example (a int, b int); insert into example values(1, 2), (2, 2), (3, 3), (4, 3); select a, last_value(a) over(order by (a)) from example; +------+----------------------------------+ | a | last_value(a) over(order by (a)) | +------+----------------------------------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | | 4 | 4 | +------+----------------------------------+ select a, last_value(a) over(order by (a) rows between current row and unbounded following) from example; +------+-----------------------------------------------------------------------------------+ | a | last_value(a) over(order by (a) rows between current row and unbounded following) | +------+-----------------------------------------------------------------------------------+ | 1 | 4 | | 2 | 4 | | 3 | 4 | | 4 | 4 | +------+-----------------------------------------------------------------------------------+