SelectDB Cloud
SQL 手册
函数
aggregate-functions
COLLECT_SET

COLLECT_SET

description

Syntax

ARRAY<T> collect_set(expr)

返回一个包含 expr 中所有去重后元素(不包括NULL)的数组,数组中元素顺序是不确定的。

notice

仅支持向量化引擎中使用

example

mysql> set enable_vectorized_engine=true;

mysql> select k1,k2,k3 from collect_test order by k1;
+------+------------+-------+
| k1   | k2         | k3    |
+------+------------+-------+
|    1 | 2022-07-05 | hello |
|    2 | 2022-07-04 | NULL  |
|    2 | 2022-07-04 | hello |
|    3 | NULL       | world |
|    3 | NULL       | world |
+------+------------+-------+

mysql> select k1,collect_set(k2),collect_set(k3) from collect_test group by k1 order by k1;
+------+-------------------+-------------------+
| k1   | collect_set(`k2`) | collect_set(`k3`) |
+------+-------------------+-------------------+
|    1 | [2022-07-05]      | [hello]           |
|    2 | [2022-07-04]      | [hello]           |
|    3 | NULL              | [world]           |
+------+-------------------+-------------------+

keywords

COLLECT_SET,COLLECT_LIST,ARRAY

© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标