hsql--行转多列
lateral view 把结果组合,产生一个支持别名表的虚拟表
select A,B from table_1
lateral view explode(B) mytable as B
[1, 2] ['a', 'b', 'c']
[3, 4] ['d', 'e', 'f']
同时把第一列和第二列拆开,类似做笛卡尔乘积
select col1,col2 from basetable
select mycol1, mycol2 from basetable
lateral view explode(col1) mytable1 as mycol1
lateral view explode(col2) mytable2 as mycol2;
3.复杂方式:
select * from tb_split;
20141018 aa|bb 7|9|0|3
20141019 cc|dd 6|1|8|5
使用方式:select datenu,des,type from tb_split
lateral view explode(split(des,"//|")) tb1 as des
lateral view explode(split(type,"//|")) tb2 as type
执行过程是先执行from到as cloumn的列过程,再执行select 和where后边的语句

浙公网安备 33010602011771号