ClickHouse/docs/en/sql-reference/aggregate-functions/reference/grouparraysorted.md
2022-04-09 07:34:21 -06:00

1.1 KiB
Raw Blame History

sidebar_position
108

groupArraySorted

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

groupArraySorted(N)(column)

Arguments

  • N The number of elements to return.

If the parameter is omitted, default value 10 is used.

Arguments

  • column The value.
  • expr — Optional. The field or expresion to sort by. If not set values are sorted by themselves.

Example

Gets the first 10 numbers:

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

Or the last 10:

SELECT groupArraySorted(10)(number, -number) FROM numbers(100)
┌─groupArraySorted(10)(number, negate(number))─┐
│ [99,98,97,96,95,94,93,92,91,90]              │
└──────────────────────────────────────────────┘