2024-06-24 12:32:52 +00:00
|
|
|
|
---
|
|
|
|
|
slug: /en/sql-reference/aggregate-functions/reference/grouparraysorted
|
|
|
|
|
sidebar_position: 146
|
|
|
|
|
---
|
2024-01-19 15:37:02 +00:00
|
|
|
|
|
|
|
|
|
# groupArraySorted {#groupArraySorted}
|
|
|
|
|
|
|
|
|
|
Returns an array with the first N items in ascending order.
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
groupArraySorted(N)(column)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Arguments**
|
|
|
|
|
|
|
|
|
|
- `N` – The number of elements to return.
|
|
|
|
|
|
|
|
|
|
- `column` – The value (Integer, String, Float and other Generic types).
|
|
|
|
|
|
|
|
|
|
**Example**
|
|
|
|
|
|
|
|
|
|
Gets the first 10 numbers:
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT groupArraySorted(10)(number) FROM numbers(100)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
┌─groupArraySorted(10)(number)─┐
|
|
|
|
|
│ [0,1,2,3,4,5,6,7,8,9] │
|
|
|
|
|
└──────────────────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gets all the String implementations of all numbers in column:
|
|
|
|
|
|
|
|
|
|
``` sql
|
2024-03-06 12:52:03 +00:00
|
|
|
|
SELECT groupArraySorted(5)(str) FROM (SELECT toString(number) as str FROM numbers(5));
|
2024-01-19 15:37:02 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
2024-03-06 12:52:03 +00:00
|
|
|
|
┌─groupArraySorted(5)(str)─┐
|
|
|
|
|
│ ['0','1','2','3','4'] │
|
|
|
|
|
└──────────────────────────┘
|
|
|
|
|
```
|