问题
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?
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.)
回答1:
Try using this in place of group_concat in Presto ::
select
a,
array_join(array_agg(b), ',')
from table
group by a
回答2:
Also, if you're looking for unique values only – an equivalent to group_concat(distinct ... separator ', ')
– try this:
array_join(array_distinct(array_agg(...)), ', ')
回答3:
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
来源:https://stackoverflow.com/questions/44142356/presto-equivalent-of-mysql-group-concat