Combine multiple rows into one space separated string

后端 未结 4 680
时光取名叫无心
时光取名叫无心 2020-12-30 05:05

So I have 5 rows like this

userid, col
--------------
1, a
1, b
2, c
2, d
3, e

How would I do query so it will look like this



        
4条回答
  •  北海茫月
    2020-12-30 05:42

    1. MySQL with duplicates: select col1, group_concat(col2) from table1 group by col1
    2. MySQL without duplicates: select col1, group_concat(distinct col2) from table1 group by col1
    3. Hive with duplicates: select col1, collect_list(col2) from table1 group by col1
    4. Hive without duplicates: select col1, collect_set(col2) from table1 group by col1

提交回复
热议问题