关于组concat:相当于MySQL的group_concat

Presto equivalent of MySQL group_concat

我是Presto的新手,希望获得与MySQL中的group_concat函数相同的功能。 以下两个是否相等? 如果没有,关于如何在Presto中重新创建group_concat功能的任何建议?

MySQL:

1
2
3
4
5
select
  a,
  group_concat(b separator ',')
from table
group by a

Presto:

1
2
3
4
5
select
  a,
  array_join(array_agg(b), ',')
from table
group by a

(在搜索group_concat功能时,将其作为建议的Presto解决方法在此找到。)


尝试使用它代替Presto中的group_concat ::

1
2
3
4
5
select
  a,
  array_join(array_agg(b), ',')
from table
group by a

另外,如果您只在寻找唯一值(等同于group_concat(distinct ... separator ', ')),请尝试以下操作:

1
array_join(array_distinct(array_agg(...)), ', ')


尽管已请求该功能,但截至该答案尚无功能。

在您的问题中提到了最接近的对等词。

1
2
3
4
5
6
7
WITH tmp AS (
SELECT 'hey' AS str1
UNION ALL
SELECT ' there'
)
SELECT array_join(array_agg(str1), ',', '') AS joined
FROM tmp