hive列转行行转列
Posted arabi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hive列转行行转列相关的知识,希望对你有一定的参考价值。
1.列转行
select t.cust_id
,concat_ws(‘,‘,collect_list(group_id)) one_pace
from (select ‘A_001‘ cust_id
,‘20191014‘ group_id
union all
select ‘A_001‘ cust_id
,‘20191015‘ group_id
union all
select ‘A_001‘ cust_id
,‘20191016‘ group_id) t
group by t.cust_id;
2.行转列
select cust_id
,one_pace
,group_id
from (select ‘A_001‘ cust_id
,‘20191014,20191015,20191016‘ one_pace
union all
select ‘A_002‘ cust_id
,‘20191014,20191015,20191016‘ one_pace
union all
select ‘A_003‘ cust_id
,‘20191014,20191015,20191016‘ one_pace) t
lateral view explode(split(one_pace,‘,‘)) num as group_id;
以上是关于hive列转行行转列的主要内容,如果未能解决你的问题,请参考以下文章