日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

impala sql清单

發(fā)布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 impala sql清单 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

創(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。