Hive 之 子查询

Hive中的子查询 
hive只支持 from和where子句中的子查询
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries
查询名称为销售和财务的两个部门的员工姓名
select e.ename from emp e where e.deptno in (select d.deptno from detp d where d.dnmae='SALE' or d.dname='ACOUNTING');
注意
    小括号
    只支持from和where
    主查询和子查询可以不是同一张表
    子查询的空值问题,有空值时,不能使用not in ,可以使用 in 
    查询不是经理的员工
    select * from emp e where e.empno not in (select e1.mgr from emp e1);
    因为子查询中含有空值,所以没有结果 
    select * from emp e where e.empno not in (select e1.mgr from emp e1 where e1.mgr is not null); 

猜你喜欢

转载自blog.csdn.net/lepton126/article/details/80415020
今日推荐