groupArray
Syntax: groupArray(x)
or groupArray(max_size)(x)
Creates an array of argument values. Values can be added to the array in any (indeterminate) order.
The second version (with the max_size
parameter) limits the size of the resulting array to max_size
elements. For example, groupArray(1)(x)
is equivalent to [any (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
.
Example
SELECT * FROM default.ck;
ββidββ¬βnameββββββ
β 1 β zhangsan β
β 1 β α΄Ία΅α΄Έα΄Έ β
β 1 β lisi β
β 2 β wangwu β
ββββββ΄βββββββββββ
Query:
select id, groupArray(10)(name) from default.ck group by id;
Result:
ββidββ¬βgroupArray(10)(name)ββ
β 1 β ['zhangsan','lisi'] β
β 2 β ['wangwu'] β
ββββββ΄βββββββββββββββββββββββ
The groupArray function will remove α΄Ία΅α΄Έα΄Έ value based on the above results.