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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM