impala學習筆記

impala學習筆記
-- 建庫
CREATE DATABASE IF NOT EXISTS database_name;
-- 在HDFS文件系統中建立數據庫,須要指定要建立數據庫的位置。
CREATE DATABASE IF NOT EXISTS database_name LOCATION hdfs_path;
-- 刪庫
DROP DATABASE IF EXISTS sample_database;
-- 刪除數據庫並刪除表
DROP database sample cascade; 
-- 建表
CREATE TABLE IF NOT EXISTS my_db.student(name STRING, age INT, contact INT );
-- 插入數據
insert into employee(ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Ramesh', 32, 'Ahmedabad', 20000 );
insert into employee values (2, 'Khilan', 25, 'Delhi', 15000 );
-- 插入新數據並覆蓋原有數據
Insert overwrite table_name values (value1, value2, value2);
-- 顯示錶結構
describe customer;
-- 改表名
ALTER TABLE my_db.customers RENAME TO my_db.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 customers;
-- 建立視圖
CREATE VIEW IF NOT EXISTS customers_view AS select name, age from customers;
-- 更新視圖
Alter view customers_view as select id, name, salary from customers;
-- 刪除視圖
Drop view customers_view;
-- 查詢結果排序
Select * from customers ORDER BY id asc;
-- 查詢結果分組
Select name, sum(salary) from customers Group BY name;
-- 聚合結果過濾
select max(salary) from customers group by age having max(salary) > 20000;
-- 查詢結果偏移
select * from customers order by id limit 4 offset 5;
-- 查詢太複雜,咱們能夠爲複雜部分定義別名,並使用Impala的with子句將它們包含在查詢中
with t1 as (select * from customers where age>25), t2 as (select * from employee where age>25) (select * from t1 union select * from t2)
-- 刪除重複值
select distinct name, age, address from customers;
相關文章
相關標籤/搜索