Relational Data - Aggregate Functions - Reference - Anylast

From FojiSoft Docs
Revision as of 18:43, 28 August 2024 by Chris.Hansen (talk | contribs) (Import ClickHouse Docs: Wed Aug 28 2024 14:43:33 GMT-0400 (Eastern Daylight Time))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

Supports the RESPECT NULLS modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is NULL or not.


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) FROM any_last_nulls;
┌─anyLast(city)─┐
│ Valencia      │
└───────────────┘