關於hive的常用命令

2021-12-30 09:50:21 字數 2205 閱讀 1947

建立表

create table employee(employee_id string,name string) row format delimited fields terminated by ',' stored as textfile;

載入資料: 本地資料位置: /home/dawn/usr/app/hadoopdata/hive/visition.txt'

load data local inpath 'file:///home/dawn/usr/app/hadoopdata/hive/visition.txt' into table visition ;

hive是不支援刪除操作的,可以從hive表中查詢出你想保留的資料,並且輸入到原來的表中

例如刪除一些記錄,可以使用

insert overwrite table t_table1 select * from t_table1 where xx=『』;

內連線內連線指的是把符合兩邊連線條件的資料查詢出來。

查詢語句

select * from employee join job on employee.employee_id=job.employee_id;

select e.employee_id,e.name,j.job_id,j.job from employee e,job j where e.employee_id = j.employee_id;

左外連線

如果 左邊有資料,右邊沒有資料,則左邊有資料的記錄的對應列返回為空。

查詢語句

select * from employee left outer join job on employee.employee_id=job.employee_id;

右外連線

如果 左邊沒有資料,右邊有資料,則右邊有資料的記錄的對應列返回為空。

查詢語句

select * from employee right outer join job on employee.employee_id=job.employee_id;

全外連線

顯示左外連線,右外連線的合集。

查詢語句

select * from employee full outer join job on employee.employee_id = job.employee_id;

左半連線

左半連線與in操作或者exists操作,效果一樣。

查詢語句

select * from employee left semi join job on employee.employee_id=job.employee_id;

in左邊的表在右邊表的範圍內。與left semi join 效果一樣。

select * from employee where employee_id in (select employee_id from job);

insert into employee select 0,decode(binary('張三'),'utf-8') from dual;

insert into employee select 1,decode(binary('李四'),'utf-8') from dual;

insert into employee select 2,decode(binary('王五'),'utf-8') from dual;

insert into employee select 4,decode(binary('趙六'),'utf-8') from dual;

insert into table visition_out select a.name, a.mon,max(a.num),sum(b.num) from (select name, substr(mon, 1, 7) mon, sum(num) num from visition g group by g. name, substr(mon, 1, 7)) a, (select name, substr(mon, 1, 7) mon, sum(num) num from visition g group by g. name, substr(mon, 1, 7)) b where a.name = b.name and a.mon >= b.mon group by a.name,a.mon;

select name, substr(mon, 1, 7) mon, sum(num) num from visition g group by g. name, substr(mon, 1, 7);

hive常用命令

進入hive目錄後執行hive命令進入命令模式 建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load d...

hive常用命令

建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load data local inpath home co...

Hive常用命令

檢視hdfs路徑 show create table table name 建表 create table tbname var1 char type1,var2 char type2 載入資料到表 刪除表 drop table tbname if expr1,expr2,expr3 expr1 判...