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
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
Use the GROUP_CONCAT aggregate function:
SELECT yt.userid,
GROUP_CONCAT(yt.col SEPARATOR ' ') AS combined
FROM YOUR_TABLE yt
GROUP BY yt.userid
The default separator is a comma (","), so you need to specify the SEPARATOR of a single space to get the output you desire.
If you want to ensure the order of the values in the GROUP_CONCAT, use:
SELECT yt.userid,
GROUP_CONCAT(yt.col ORDER BY yt.col SEPARATOR ' ') AS combined
FROM YOUR_TABLE yt
GROUP BY yt.userid
I'm pretty sure that you can't do this using Hive QL. However, it should be possible to do so if you write your own Map/Reduce scripts - see this tutorial to get started.