hive列转行

一、问题

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;

posted @ 2016-09-28 14:33  听风者~  阅读(3264)  评论(0)    收藏  举报