impala sql清单
創(chuàng)建數(shù)據(jù)庫
CREATE DATABASE IF NOT EXISTS database_name;
查看所有數(shù)據(jù)庫
show databases
刪除數(shù)據(jù)庫
DROP DATABASE IF EXISTS sample_database;
進(jìn)入數(shù)據(jù)庫
use dbname
?
創(chuàng)建表
CREATE TABLE IF NOT EXISTS test.student
(name STRING, age INT, contact INT );
查看所有表
show tables
?
/指定HDFS路徑建庫
為了在HDFS文件系統(tǒng)中創(chuàng)建數(shù)據(jù)庫,需要指定要創(chuàng)建數(shù)據(jù)庫的位置,如下所示。
CREATE DATABASE IF NOT EXISTS database_name LOCATION hdfs_path;
實測會報無權(quán)限
CREATE DATABASE IF NOT EXISTS hdfstest LOCATION "/db/hdfstest";
改個有權(quán)限的目錄即可:
CREATE DATABASE IF NOT EXISTS hdfstest LOCATION "/user/impala/db/hdfstest";
注:通過hadoop fs -ls /user類似命令找到有權(quán)限的目錄
建表后會在hdfs數(shù)據(jù)庫目錄下創(chuàng)建表的目錄
插入數(shù)據(jù)后數(shù)據(jù)會存在表目錄中。
?
insert
create table employee (Id INT, name STRING, age INT,address STRING, salary BIGINT);
insert into employee (ID,NAME,AGE,ADDRESS,SALARY)VALUES (1, 'Ramesh', 32, 'Ahmedabad', 20000 );
///查詢
select * from employee
排序
select id,name,age,address,salary from employee order by id
select * from employee order by salary desc nulls last
?
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
可以使用關(guān)鍵字ASC或DESC分別按升序或降序排列表中的數(shù)據(jù)。
以同樣的方式,如果我們使用NULLS FIRST,表中的所有空值都排列在頂行; 如果我們使用NULLS LAST,包含空值的行將最后排列。
?
分組查詢
select name,sum(salary) from employee group by name
select name,sum(salary) from employee group by name having sum(salary)>20000
翻頁查詢
select * from employee order by id limit 2 offset 2
?
///union
select * from employee order by id limit 2
union
select * from employee order by id limit 4
?
select * from employee order by id limit 2
union all
select * from employee order by id limit 4
?
with
with x as (select 1), y as (select 2) (select * from x union y);
?
with t1 as (select * from employee where age>30),
t2 as (select * from employee where age>25)
(select * from t1 union all select * from t2);
?
distinct
select distinct id,name from employee;
?
/覆蓋插入(表的所有數(shù)據(jù)都被刪除)
Insert?overwrite?employee?values?(1,?'Ram',?26,??
'Vishakhapatnam',?37000?)?
?
///獲取表的描述(表結(jié)構(gòu))
describe employee
?
改表名
ALTER TABLE [old_db_name.]old_table_name RENAME TO [new_db_name.]new_table_name
ALTER TABLE hdfstest.employee RENAME TO hdfstest.users;
?
/添加列
ALTER TABLE users ADD COLUMNS (account_no BIGINT, phone_no BIGINT);
刪除列
ALTER TABLE users DROP account_no;
/更改列名和類型
ALTER TABLE users CHANGE phone_no e_mail string;
刪除表
drop table if exists my_db.student;
///清空表
truncate table_name;
?
?
創(chuàng)建視圖
CREATE VIEW IF NOT EXISTS users_view AS
select name, age from users;
/修改視圖
alter view users_view AS
select name, age,e_mail from users;
//刪除視圖
drop view users_view
?
參考鏈接:https://www.w3cschool.cn/impala/
總結(jié)
以上是生活随笔為你收集整理的impala sql清单的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ie直接编辑网页
- 下一篇: 商品评价判别,文本分类——学习笔记