ARRAY_AGG

description

Syntax

ARRAY_AGG(col)

将一列中的值(包括空值 null)串联成一个数组,可以用于多行转一行(行转列)。

notice

  • 数组中元素不保证顺序。
  • 返回转换生成的数组。数组中的元素类型与 col 类型一致。

example

  1. mysql> select * from test_doris_array_agg;
  2. +------+------+
  3. | c1 | c2 |
  4. +------+------+
  5. | 1 | a |
  6. | 1 | b |
  7. | 2 | c |
  8. | 2 | NULL |
  9. | 3 | NULL |
  10. +------+------+
  11. mysql> select c1, array_agg(c2) from test_doris_array_agg group by c1;
  12. +------+-----------------+
  13. | c1 | array_agg(`c2`) |
  14. +------+-----------------+
  15. | 1 | ["a","b"] |
  16. | 2 | [NULL,"c"] |
  17. | 3 | [NULL] |
  18. +------+-----------------+

keywords

ARRAY_AGG