2021-05-14

hive 多行转多列

+----------------------------------+------------------------------------------+------------------------------------------+
| test_tpl_type_lvl2_f.album_type  | test_tpl_type_lvl2_f.lvl1_tpl_type_desc  | test_tpl_type_lvl2_f.lvl2_tpl_type_desc  |
+----------------------------------+------------------------------------------+------------------------------------------+
| a                                | 影集                                     | 送祝福                                   |
| b                                | 影集                                     | MV                                       |
| c                                | 影集                                     | 极速影集                                 |
| d                                | 影集                                     | 图文                                     |
| e                                | 视频                                     | 视频剪辑                                 |
| f                                | 影集                                     | 经典模板                                 |
| g                                | 视频                                     | 发视频                                   |
| h                                | 未知                                     | 未知                                     |
| i                                | 其他                                     | 其他                                     |
+----------------------------------+------------------------------------------+------------------------------------------+
+---------------------+--------+------+---------+-------+---------+---------+--------+-------+-----+
|        title        |  a     |  b   |   c     |  d    |   e     |   f     |  g     |  h    |  i  |
+---------------------+--------+------+---------+-------+---------+---------+--------+-------+-----+
| lvl1_tpl_type_desc  | 影集   | 影集 | 影集    | 影集  | 视频    | 影集    | 视频   | 未知  | 其他|
| lvl2_tpl_type_desc  | 送祝福 | MV   | 极速影集| 图文  | 视频剪辑| 经典模板| 发视频 | 未知  | 其他|
+---------------------+--------+------+---------+-------+-------  +---------+--------+-------+-----+

 

 

select
title,
max(case when album_type = 'a' then value else '' end) as a,
max(case when album_type = 'b' then value else '' end) as b,
max(case when album_type = 'c' then value else '' end) as c,
max(case when album_type = 'd' then value else '' end) as d,
max(case when album_type = 'e' then value else '' end) as e,
max(case when album_type = 'f' then value else '' end) as f,
max(case when album_type = 'g' then value else '' end) as g,
max(case when album_type = 'h' then value else '' end) as h,
max(case when album_type = 'i' then value else '' end) as i
from
(select
album_type,
c.a as title,
c.b as value
from test_tpl_type_lvl2_f
lateral view explode(map(
'lvl1_tpl_type_desc',lvl1_tpl_type_desc,
'lvl2_tpl_type_desc',lvl2_tpl_type_desc))c as a,b)t1
group by title;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值