hive中的子查询改join操作(转)

这些子查询在oracle和mysql等数据库中都能执行,但是在hive中却不支持,但是我们可以把这些查询语句改为join操作:
--  1.子查询
select 
    * 
from 
    A a 
where 
    a.update_time = (select min(b.update_time) from A b)

--  2.in操作
select 
    * 
from 
    A a
where 
    a.dept = 'IT' 
and 
    a.num in (select b.num from B b where b.flag = '1') 

改为join操作如下:
--  1
select 
    t2.* 
from 
    (select min(a.update_time) upt from A a) t1 
left outer join
    (select b.* from A b) t2 
on
    t1.upt = t2.update_time

--  2
select 
    a.* 
from 
    A a 
left semi join
    B b
on (a.num = b.num and a.dept = 'IT' and b.flag = '1') 
--------------------- 
原文:https://blog.csdn.net/qq_20641565/article/details/52851700 
原文地址:https://www.cnblogs.com/peizhe123/p/9870872.html