这个需求会稍微复杂一点:
首先我们有一张 table_A表:
id | code |
---|---|
1001 | 0,1,3,4 |
1002 | 2,3 |
1003 | 0,24 |
还有一张 code表
code | code_value |
---|---|
0 | 法人 |
1 | 董事 |
2 | 股东 |
3 | 监事 |
4 | 高管 |
我们现在的需求是想把code表的value按照code值给映射回table_A ,如下:
id | code |
---|---|
1001 | 法人,董事,监事,高管 |
1002 | 股东,监事 |
1003 | 法人,股东,高管 |
使用Hive SQL来实现具体如下:
一、先进行按字段拆分,列转行
其语法如下:
select f.id, f.code, new_code
from
(select id,code_value from table_A
where 字段x = 条件x
) f
lateral view explode