LAST
Description
Returns the last element of the specified source column for each element in a group.
LAST can be applied to any data type. The data type of the result is the same as the input column data type.
Syntax
LAST ( table.input_column [, ORDER BY table.column [ASC|DESC] ] )
table.input_column: The column which should be aggregated.
ORDER BY (optional): Elements of the specified column are used to determine the last element.
ASC
orDESC
can be specified to use ascending or descending ordering. If the order direction is not specified, the ascending (ASC
) order is used. UsingLAST
with descending order is equivalent to using FIRST with ascending order.
NULL handling
NULL values are ignored, so they do not influence the result. If all the values of a group are NULL, the result for this group is also NULL.
Examples
[1] This example computes the last element of a column. | ||||||||||
| ||||||||||
|
[2] This example computes the last value grouped by country. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|
[3] This example demonstrates the use of the optional ORDER BY clause. | |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
|
[4] This example computes the last element in a group with null values. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|