码迷,mamicode.com
首页 > 其他好文 > 详细

hive的常用HQL语句

时间:2018-07-27 16:17:16      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:null   min   data   dep   nbsp   orm   rect   效率   聚合函数   

1、过滤条件
where 、limit、 distinct、 between and 、 null、 is not null
select * from emp where sal > 3000;
select * from emp limit 1;
select distinct deptno from emp;
select * from emp where sal between 2000 and 3000;
select ename from emp where comm is null;
select ename from emp where comm is not null;

2、聚合函数
count、 sum、 avg、 max、 min 、group by、 having

select count(1) from emp;
select count(*) from emp; -》运行效率较低

select avg(sal) avg_sal from emp;
select deptno,avg(sal) from emp group by deptno;
select deptno,avg(sal) avg_sal from emp group by deptno having avg_sal > 2000;

3、join
等值join
左join left
右join right
全join full

 

select e.empno,e.ename,d.deptno,e.sal from emp e join dept d on e.deptno=d.deptno;

select e.empno,e.ename,d.deptno,e.sal from emp e left join dept d on e.deptno=d.deptno;

select e.empno,e.ename,d.deptno,e.sal from emp e right join dept d on e.deptno=d.deptno;

select e.empno,e.ename,d.deptno,e.sal from emp e full join dept d on e.deptno=d.deptno;

4、hive中的几种排序方式
1、order by
select * from emp order by sal;
2、sort by

insert overwrite local directory ‘/opt/datas/emp_sort‘ row format delimited fields terminated by ‘\t‘ select * from emp sort by sal;

3、distribute by

insert overwrite local directory ‘/opt/datas/emp_dist‘ row format delimited fields terminated by ‘\t‘ select * from emp distribute by deptno sort by sal;

4、cluster by
=distribute by+sort by

insert overwrite local directory ‘/opt/datas/emp_cls‘ row format delimited fields terminated by ‘\t‘ select * from emp cluster by sal;

hive的常用HQL语句

标签:null   min   data   dep   nbsp   orm   rect   效率   聚合函数   

原文地址:https://www.cnblogs.com/wakerwang/p/hive.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!