1. 程式人生 > >hive中的子查詢改join操作

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')