hive常用命令

创建表
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常用命令)