赞
踩
/********* Begin *********/ CREATE DATABASE IF NOT EXISTS test1 LOCATION '/hive/test1'; USE test1; CREATE TABLE IF NOT EXISTS test1.student( Sno INT, name STRING, age INT, sex STRING, score STRUCT <Chinese:FLOAT, Math:FLOAT, English:FLOAT> ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' COLLECTION ITEMS TERMINATED BY '-'; load data local inpath '/home/student.txt' overwrite into table student; /********* End *********/ select * from student;
--Begin
USE test2;
select * from student;
select * from student where age > 17 and sex = "female";
select * from student where score.Chinese > 90;
select * from student limit 3;
select * from student sort by age desc limit 2;
--End
--Begin --使用test3数据库 use test3; --复制student表两份,分别名为:student2、student3 CREATE TABLE IF NOT EXISTS student2 LIKE student; CREATE TABLE IF NOT EXISTS student3 LIKE student; --以覆盖插入的方式把student表中前两条数据插入到student2中 insert overwrite table student2 select * from student limit 2; --评测代码,勿删 select * from student2; --以追加插入的方式把student表中前两条数据插入到student2中 insert into table student2 select * from student limit 2; --评测代码,勿删 select * from student2; --以覆盖插入的方式把student表中年龄大于17岁的数据插入到student2、student3中 from student ii insert overwrite table student2 select * where ii.age > 17 insert overwrite table student3 select * where ii.age > 17; --评测代码,勿删 select * from student2; select * from student3; --以追加插入的方式把student表中的男生数据插入到student2,以覆盖插入的方式把女生数据插入到student3中 from student ii insert into table student2 select * where ii.sex = 'male' insert overwrite table student3 select * where ii.sex = 'female'; --评测代码,勿删 select * from student2; select * from student3; --End
--使用test4数据库
use test4;
--Begin
insert overwrite local directory '/home/test4'
select * from student limit 2;
FROM student
insert overwrite local directory '/home/test4_1'
select * where sex = 'male'
insert overwrite local directory '/home/test4_2'
select * where sex='female'
--End
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。