创建表studnet:
create table student(name string,subject string,score decimal(4,1))
row format delimited
fields terminated by ‘|‘;
导入数据:
load data local inpath ‘/home/hadoop/hivetestdata/student.txt‘ into table student;
列转为行演示:
hive (hive)> select name,concat_ws(‘,‘,collect_set(subject)) from student group by name;
huahua chinese,math
xiaomingenglish,chinese,math
hive (hive)> select name,concat_ws(‘,‘,collect_set(concat(subject,‘=‘,score))) from student group by name;
huahuachinese=80,math=89.5
xiaomingenglish=92,chinese=98,math=89.5