I'm new to Presto and looking to get the same functionality as the group_concat function in MySQL. Are the following two equivalent? If not, any suggestions for how I can recreate the group_concat functionality in Presto?
我是Presto的新手,希望获得与MySQL中的group_concat功能相同的功能。以下两个是等价的吗?如果没有,有关如何在Presto中重新创建group_concat功能的任何建议?
MySQL:
select
a,
group_concat(b separator ',')
from table
group by a
Presto:
select
a,
array_join(array_agg(b), ',')
from table
group by a
(Found this as a suggested Presto workaround here when searching group_concat functionality.)
(在搜索group_concat功能时,可以在此处找到建议的Presto解决方法。)
3 个解决方案
#1
4
Try using this in place of group_concat in Presto ::
尝试使用它代替Presto中的group_concat ::
select
a,
array_join(array_agg(b), ',')
from table
group by a
#2
2
There's no function as of this answer, though the feature has been requested.
尽管已经请求了此功能,但此答案没有任何功能。
The closest equivalent is mentioned in your question.
您的问题中提到了最接近的等价物。
WITH tmp AS (
SELECT 'hey' AS str1
UNION ALL
SELECT ' there'
)
SELECT array_join(array_agg(str1), ',', '') AS joined
FROM tmp
#3
2
Also, if you're looking for unique values only – an equivalent to group_concat(distinct ... separator ', ')
– try this:
此外,如果您只查找唯一值 - 相当于group_concat(distinct ... separator',') - 请尝试以下操作:
array_join(array_distinct(array_agg(...)), ', ')
#1
4
Try using this in place of group_concat in Presto ::
尝试使用它代替Presto中的group_concat ::
select
a,
array_join(array_agg(b), ',')
from table
group by a
#2
2
There's no function as of this answer, though the feature has been requested.
尽管已经请求了此功能,但此答案没有任何功能。
The closest equivalent is mentioned in your question.
您的问题中提到了最接近的等价物。
WITH tmp AS (
SELECT 'hey' AS str1
UNION ALL
SELECT ' there'
)
SELECT array_join(array_agg(str1), ',', '') AS joined
FROM tmp
#3
2
Also, if you're looking for unique values only – an equivalent to group_concat(distinct ... separator ', ')
– try this:
此外,如果您只查找唯一值 - 相当于group_concat(distinct ... separator',') - 请尝试以下操作:
array_join(array_distinct(array_agg(...)), ', ')