第1节 IMPALA:10、基本查询语法;11、数据加载的4种方式

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 

转载于:https://www.cnblogs.com/mediocreWorld/p/11141351.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值