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
userid, combined
1, a b
2, c d
3, e
You can concatenate rows into single string using COALESCE method. This COALESCE method can be used in SQL Server version 2008 and higher. All you have to do is, declare a varchar variable and inside the coalesce, concat the variable with comma and the column, then assign the COALESCE to the variable.
In hive you can use
SELECT userid, collect_set(combined) FROM tabel GROUP BY user_id;
collect_set removes duplicated. If you need to keep them you can check this post:
COLLECT_SET() in Hive, keep duplicates?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With