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;