一、问题
hive如何将
a b 1
a b 2
a b 3
c d 4
c d 5
c d 6
变为:
a b 1,2,3
c d 4,5,6
二、数据
test.txt
a b 1
a b 2
a b 3
c d 4
c d 5
c d 6
三、答案
1.建表
drop table test;
create table test
(
col1 string,
col2 string,
col3 string
);
load data local inpath '/home/test.txt' into table test;
2.处理
select col1,col2,concat_ws(',',collect_set(col3))
from test
group by col1,col2;