9.3、 创建数据库表
创建student表
CREATE TABLE IF NOT EXISTS mydb1.student (name STRING, age INT, contact INT );
创建employ表
create table employee (Id INT, name STRING, age INT,address STRING, salary BIGINT);
9.3.1、 数据库表中插入数据
insert into employee (ID,NAME,AGE,ADDRESS,SALARY)VALUES (1, 'Ramesh', 32, 'Ahmedabad', 20000 );
insert into employee values (2, 'Khilan', 25, 'Delhi', 15000 );
Insert into employee values (3, 'kaushik', 23, 'Kota', 30000 );
Insert into employee values (4, 'Chaitali', 25, 'Mumbai', 35000 );
Insert into employee values (5, 'Hardik', 27, 'Bhopal', 40000 );
Insert into employee values (6, 'Komal', 22, 'MP', 32000 );
数据的覆盖
Insert overwrite employee values (1, 'Ram', 26, 'Vishakhapatnam', 37000 );
执行覆盖之后,表中只剩下了这一条数据了
另外一种建表语句
create table customer as select * from employee;
9.3.2、 数据的查询
select * from employee;
select name,age from employee;
9.3.3、 删除表
DROP table mydb1.employee;
9.3.4、 清空表数据
truncate employee;
9.3.5、 创建视图
CREATE VIEW IF NOT EXISTS employee_view AS select name, age from employee;
9.3.6、 查看视图数据
select * from employee_view;
9.4、 order by语句
基础语法
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
Select * from employee ORDER BY id asc;
9.5、group by 语句
Select name, sum(salary) from employee Group BY name;
9.6、 having 语句
基础语法
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
按年龄对表进行分组,并选择每个组的最大工资,并显示大于20000的工资
select max(salary) from employee group by age having max(salary) > 20000;
9.7、 limit语句
select * from employee order by id limit 4;
10、impala当中的数据表导入几种方式
第一种方式,通过load hdfs的数据到impala当中去
create table user(id int ,name string,age int ) row format delimited fields terminated by "\t";
准备数据user.txt并上传到hdfs的 /user/impala路径下去
1 hello 15
2 zhangsan 20
3 lisi 30
4 wangwu 50
加载数据的4种方法:
第一种方式:
load data inpath '/user/impala/' into table user;
注意:没法使用load data local的方式,加载本地目录中的数据!
查询加载的数据
select * from user;
如果查询不不到数据,那么需要刷新一遍数据表
refresh user;
第二种方式:
create table user2 as select * from user;
第三种方式:
insert into
第四种:
insert into select