You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by zhengzhongni <zh...@outlook.com> on 2020/11/30 03:41:19 UTC

Flink SQL 是否存在类似MySQL的group_concat函数

各位社区大佬,
您好!


不知Flink SQL中是否存在类似MySQL的group_concat函数的功能:
例如:
数据:
+------+-------+
| Id   | Name  |
+------+-------+
|   10 | Larry |
|   11 | Mike  |
|   12 | John  |
|   10 | Elon  |
|   10 | Bob   |
|   11 | Sam   |
+------+———+
执行SQL :select Id,group_concat(Name SEPARATOR ',') as resultName from test group by Id;
期望得到的结果:
+------+-----------------+
| Id   | resultName      |
+------+-----------------+
|   10 | Larry,Elon,Bob  |
|   11 | Mike,Sam        |
|   12 | John            |
+------+————————+


这种在统计最近一段时间用户的登录IP,登录的设备等场景会用到,不知道目前的Flink SQL是否有类似的函数?


期待您的回复,非常感谢~~

Re: Flink SQL 是否存在类似MySQL的group_concat函数

Posted by Jark Wu <im...@gmail.com>.
I think you are looking for LISTAGG [1] which is more SQL standard
compliant.

Best,
Jark

[1]:
https://ci.apache.org/projects/flink/flink-docs-master/dev/table/functions/systemFunctions.html

On Mon, 30 Nov 2020 at 11:41, zhengzhongni <zh...@outlook.com> wrote:

> 各位社区大佬,
> 您好!
>
>
> 不知Flink SQL中是否存在类似MySQL的group_concat函数的功能:
> 例如:
> 数据:
> +------+-------+
> | Id   | Name  |
> +------+-------+
> |   10 | Larry |
> |   11 | Mike  |
> |   12 | John  |
> |   10 | Elon  |
> |   10 | Bob   |
> |   11 | Sam   |
> +------+———+
> 执行SQL :select Id,group_concat(Name SEPARATOR ',') as resultName from test
> group by Id;
> 期望得到的结果:
> +------+-----------------+
> | Id   | resultName      |
> +------+-----------------+
> |   10 | Larry,Elon,Bob  |
> |   11 | Mike,Sam        |
> |   12 | John            |
> +------+————————+
>
>
> 这种在统计最近一段时间用户的登录IP,登录的设备等场景会用到,不知道目前的Flink SQL是否有类似的函数?
>
>
> 期待您的回复,非常感谢~~