Is there any way to combine/concat the fields within one column by grouping them. Eg:
col1 col2
1 aa
1 bb
1 cc
2 dd
2 ee
I want to query something like :
select col1, concat(col2) from tableName group by col1;
Output should be :
1 aa,bb,cc
2 dd,ee
Is there any function in hive to do this ?
Suppose you have a table
test
as follows:You can use the
HIVE
functioncollect_set
:But note that
collect_set
returns a set of objects with duplicate elements eliminated.You can find more details at the Language Manual Wiki.
you can use concat_ws() and collect_list() to achieve this....
Something like
"," is the seperator in the above query.