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.****.net/jiantianming2/article/details/79189672
select test1,test2,concat_ws(',',collect_set(cast(id as string))) as set
from demo group by test1,test2
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