>create table school.t_stu_subject(id int,name string,subjects array)
>row format delimited fields terminated by ','
> collection items terminated by ':';
show databases;
use school;
show tables;
表格中出现如下数据:
vi t_stu_subject
1,zhangsan,化学:物理:数学:语文
2,lisi,化学:数学:生物:生理:卫生
3,wangwu,化学:语文:英语:体育:生物
load data local inpath '/root/t_stu_subject' into table school.t_stu_subject;
在hdp-4中查看数据是否插入:
select * from t_stu_subject;
结果图如下:
select explode(subjects) from school.t_stu_subject;
结果图如下:
select distinct tmp.sub from (select explode(subjects) as sub from t_stu_subject) tmp;
结果图如下: