HIVE :行列转换
2019-08-19 本文已影响0人
惊不意外
举个栗子
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
行转列 ==>
select
col1,
col2,
concat_ws(',',collect_set(col3))
from table_test
group by col1,col2;
列转行 <==
select col1, col2, col5
from table_test a
lateral view explode(split(col3,',')) b AS col5