天天看點

hive sql的行轉列,列轉行

資料:

a b 1

a b 2

a b 3

結果:

a b 1,2,3

處理過程:

create table tmp_test(col1 string,col2 string,col3 string)

select col1,col2,concat_ws(’,’,collect_set(col3)) from tmp_test group by col1,col2;

二、列轉行

select col1,col2,col5 from tmp_test a lateral view explode(split(col3,’,’)) b AS col5;器

繼續閱讀