mysql和hive的行列转换
hive
演示单列转为多行数据
lateral view explode函数
select name, subject_list from student2 stu2 lateral view explode(split(stu2.subject_score_list,’,’))stu_subj as subject_list; ----别名一定不要忘记
多行转单列 (根据主键,进行多行合并一列)
使用函数:concat_ws(’,’,collect_set(column))
说明:collect_list 不去重,collect_set 去重。 column 的数据类型要求是 string
group by + 主键
select name,concat_ws(’,’,collect_set(concat(subject,’=’,score))) from student group by name;
mysql
主要使用聚合函数sum+case when