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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM