hive行转列,列转行实践

drop table demo;
create table demo
(
test1 string,
test2 string,
id string
)
row format delimited fields terminated by '\t'
stored as textfile;


或者


1.建表

drop table demo;
create table demo
(
test1 string,
test2 string,
id string
)
row format delimited fields terminated by '\t'
stored as textfile;


load data local inpath '/home/carson/test.txt' into table demo;

https://blog.csdn.net/jiantianming2/article/details/79189672 

 

hive行转列,列转行实践_第1张图片

select test1,test2,concat_ws(',',collect_set(cast(id as string))) as set 
from demo group by test1,test2

 

hive行转列,列转行实践_第2张图片

with temp as(select test1,test2,concat_ws(',',collect_set(cast(id as string))) as set 
from demo group by test1,test2)


select test1, test2, id from temp a 
lateral view explode(split(set,','))  b AS id

 

 hive行转列,列转行实践_第3张图片

https://blog.csdn.net/jiantianming2/article/details/79189672 

你可能感兴趣的:(hive)