array_agg
aggregate function
Applies to: Databricks SQL
Databricks Runtime 10.4 LTS and above
Returns an array consisting of all values in expr
within the group. This function is a synonym for collect_list aggregate function.
Syntax
array_agg ( [ALL | DISTINCT] expr ) [FILTER ( WHERE cond ) ]
This function can also be invoked as a window function using the OVER
clause.
Arguments
expr
: An expression of any type.cond
: An optional boolean expression filtering the rows used for aggregation.
Returns
An ARRAY of the argument type.
The order of elements in the array is non-deterministic.
NULL
values are excluded.
If DISTINCT
is specified the function collects only unique values and is a synonym for collect_set aggregate function.
Examples
> SELECT array_agg(col) FROM VALUES (1), (2), (NULL), (1) AS tab(col);
[1,2,1]
> SELECT array_agg(DISTINCT col) FROM VALUES (1), (2), (NULL), (1) AS tab(col);
[1,2]
Related functions
Tilbakemeldinger
https://aka.ms/ContentUserFeedback.
Kommer snart: Gjennom 2024 faser vi ut GitHub Issues som tilbakemeldingsmekanisme for innhold, og erstatter det med et nytt system for tilbakemeldinger. Hvis du vil ha mer informasjon, kan du se:Send inn og vis tilbakemelding for