一、列转行
使用函数:lateral view explode(split(column, ',')) num
SQL代码
select id,tag,tag_new
from t_row_to_column_tmp lateral view explode(split(tag, ',')) num as tag_new
where id=212022894;
-- select a.da_db_id,reason from jsd_execute_output_java a
lateral view explode(split(a.output_otherreason,',')) b as reason
where a.dt='2018-06-04' and a.ht='15' -- 列转行 (对某列拆分,一列拆多行)
二、行转列 (根据主键,进行多行合并一列)
使用函数:concat_ws(',',collect_set(column))
说明:collect_list 不去重,collect_set 去重。 column 的数据类型要求是 string
select id, concat_ws(',',collect_set(tag_new)) as tag_col
from t_column_to_row group by id;
select id, concat_ws(',',collect_list(tag_new)) as tag_col from t_column_to_row group by id;