赞
踩
presto中的列转行函数cross join unnest类似于hive中的侧写表lateral view explode,可以把一行转为多行。
把name字段用逗号分割后转为多行:
select id,new_name from table
cross join unnest(split(name,',')) as tmp(new_name );
注意:
cross join unnest会自动过滤掉字段值为空的数据,要保留全部数据可以这样写:
select id,new_name from table
cross join unnest(split(name,',')) as tmp(new_name )
union all
select id,new_name from table
where name is null;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。