ReferenceSQL ReferenceAggregate Functions

groupArrayLast

Creates an array of the last argument values.

This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See SQL interface scope.

Creates an array of the last argument values. For example, groupArrayLast(1)(x) is equivalent to [anyLast(x)]. In some cases, you can still rely on the order of execution. This applies to cases when SELECT comes from a subquery that uses ORDER BY if the subquery result is small enough.

Syntax

groupArrayLast(max_size)(x)

Parameters

  • max_size — Maximum size of the resulting array. UInt64

Arguments

  • max_size — Maximum size of the resulting array. UInt64
  • x — Argument (column name or expression). Any

Returned value

Returns an array of the last argument values. Array(T)

Examples

Usage example

SELECT groupArrayLast(2)(number+1) numbers FROM numbers(10);
┌─numbers─┐
│ [9,10]  │
└─────────┘

Comparison with groupArray

-- Compare with groupArray (first values)
SELECT groupArray(2)(number+1) numbers FROM numbers(10);
┌─numbers─┐
│ [1,2]   │
└─────────┘

Introduced in version 23.1.0.