mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 02:41:59 +00:00
1.3 KiB
1.3 KiB
slug | sidebar_position |
---|---|
/en/sql-reference/aggregate-functions/reference/anylast | 105 |
anyLast
Selects the last value encountered, ignoring any NULL
values by default. The result is just as indeterminate as for the any function.
Syntax
anyLast(column) [RESPECT NULLS]
Parameters
column
: The column name.
:::note
By default, the anyLast
function never returns NULL
. However, it supports the RESPECT NULLS
modifier after the function name, which will ensure the function selects the last value passed, regardless of whether it is NULL
or not.
Alias: anyLastRespectNulls
:::
Returned value
- The last value encountered.
Example
Query:
CREATE TABLE any_last_nulls (city Nullable(String)) ENGINE=Log;
INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL);
SELECT anyLast(city), anyLastRespectNulls(city) FROM any_last_nulls;
┌─anyLast(city)─┬─anyLastRespectNulls(city)─┐
│ Valencia │ ᴺᵁᴸᴸ │
└───────────────┴───────────────────────────┘