简体   繁体   English

将多个列组合到配置单元中的单个列中

[英]combining multiple columns in to single columns in hive

I have one table shown in below. 我有一张桌子如下所示。

Id   v1  v2  v3
 A   01  03  23
 B   11  21  05
 C   02  10  24
 D   22  14  23

here first column has id and it's related with three columns. 这里第一列有id,它与三列有关。 SO i have to combine that three column into one single column with related id. 所以我必须将这三列合并为一个具有相关id的单列。

For example. 例如。

id  value
A    01
A    03
A    23
B    11
B    21
B    05
.    ..
.    ..

So i have to done this in to hive so please let me know. 所以我必须做到这一点,所以请让我知道。

insert into table result_table select Id, v1 as value from orig_table;
insert into table result_table select Id, v2 as value from orig_table;
insert into table result_table select Id, v3 as value from orig_table;
select Id,value from result_table;

or 要么

select Id, value 
       from orig_table LATERAL VIEW explode(array(v1,v2,v3)) orig_table_alias AS value;
select id, v1
from table
union all
select id, v2
from table
union all
select id, v3
from table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM