ReferenceSQL ReferenceAggregate Functions

groupArraySorted

Returns an array with the first N items in ascending order.

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.

Returns an array with the first N items in ascending order.

Syntax

groupArraySorted(N)(column)

Parameters

  • N — The number of elements to return. UInt64

Arguments

  • column — Column for which to group into an array. Any

Returned value

Returns an array with the first N items in ascending order. Array

Examples

Getting first 10 numbers

SELECT groupArraySorted(10)(number) FROM numbers(100);
┌─groupArraySorted(10)(number)─┐
│ [0,1,2,3,4,5,6,7,8,9]        │
└──────────────────────────────┘

String sorting example

SELECT groupArraySorted(5)(str) FROM (SELECT toString(number) AS str FROM numbers(5));
┌─groupArraySorted(5)(str)─┐
│ ['0','1','2','3','4']    │
└──────────────────────────┘

Introduced in version 24.2.0.