Hive进阶_Hive的表连接

等值连接

select e.empno, d.deptno
from emp e, dept d
where e.deptno=d.deptno;

不等值连接

select e.empno, e.ename, e.sal, s.grade
from emp e, salgrade s
where e.sal between s.losal and s.hisal;

外连接
(取交集)

select d.deptno, d.dname, count(e.empno)
from emp e, dept d
where e.deptno=d.deptno
group by d.deptno, d.dname;

(右外连接)

select d.deptno, d.dname, count(e.empno)
from emp e right outer join dept d
on(e.deptno=d.deptno) 
group by d.deptno, d.dname;

自连接

select e.ename,b.ename
from emp e, emp b
where e.mgr=b.empno;

 

posted @ 2017-01-24 14:15  天天好心情啊  阅读(243)  评论(0编辑  收藏  举报