ARRAY_AGG

description

Syntax

ARRAY_AGG(col)

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

notice

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

example

1. mysql> select * from test_doris_array_agg;

3. +------+------+

5. | c1   | c2   |

7. +------+------+

9. |    1 | a    |

11. |    1 | b    |

13. |    2 | c    |

15. |    2 | NULL |

17. |    3 | NULL |

19. +------+------+

21. mysql> select c1, array_agg(c2) from test_doris_array_agg group by c1;

23. +------+-----------------+

25. | c1   | array_agg(`c2`) |

27. +------+-----------------+

29. |    1 | ["a","b"]       |

31. |    2 | [NULL,"c"]      |

33. |    3 | [NULL]          |

35. +------+-----------------+

keywords

ARRAY_AGG