Presto equivalent of MySQL group_concat

后端 未结 3 1281
灰色年华
灰色年华 2020-12-08 21:18

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 r

相关标签:
3条回答
  • 2020-12-08 21:38

    Try using this in place of group_concat in Presto ::

    select 
      a,
      array_join(array_agg(b), ',')
    from table
    group by a
    
    0 讨论(0)
  • 2020-12-08 21:45

    Also, if you're looking for unique values only – an equivalent to group_concat(distinct ... separator ', ') – try this:

    array_join(array_distinct(array_agg(...)), ', ')
    
    0 讨论(0)
  • 2020-12-08 21:53

    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
    
    0 讨论(0)
提交回复
热议问题