MySQL组的Presto等价物

MySQL组的Presto等价物,mysql,presto,group-concat,trino,Mysql,Presto,Group Concat,Trino,我是Presto的新手,希望获得与MySQL中的group_concat函数相同的功能。以下两项是否相等?如果没有,对如何在Presto中重新创建group_concat功能有何建议 MySQL: select a, group_concat(b separator ',') from table group by a 普雷斯托: select a, array_join(array_agg(b), ',') from table group by a (在搜索group

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

MySQL:

select 
  a,
  group_concat(b separator ',')
from table
group by a
普雷斯托:

select 
  a,
  array_join(array_agg(b), ',')
from table
group by a

(在搜索group_concat功能时,发现这是一个建议的预处理方法。)

截至此答案,没有任何功能

你的问题中提到了最接近的等价物

WITH tmp AS (
SELECT 'hey' AS str1
UNION ALL
SELECT ' there'
)
SELECT array_join(array_agg(str1), ',', '') AS joined
FROM tmp

试着用它来代替Presto中的组_concat::

select 
  a,
  array_join(array_agg(b), ',')
from table
group by a

此外,如果您只寻找唯一值–相当于
group_concat(distinct…separator',)
–请尝试以下方法:

array_join(array_distinct(array_agg(...)), ', ')
我发现(在这个实现distinct
group\u concat
)的特殊情况下,使用嵌套查询手动获取
distinct
值比
array\u distinct
UDF执行得更好。但我不确定这是否是普遍正确的