2017-03-17 52 views
1

首先,我使用的查詢:蜂巢:使用選擇內選擇

select name 
from tab1 
where id in (select id 
      from (select id,count(id) as a 
        from tab2 
        group by id 
        order by a desc limit 1) ; 

,我才知道,裏面選擇選擇是不可能的蜂巢。 所以我用變量修改它。

set var1= select count(id) as a from tab2 group by id order by a desc limit 1; 

select name from tab1 group by name having count(id)='${hiveconf:var1}'; 

但在'${hiveconf:var1}'的地方,查詢得到取代的,並再次得到同樣的錯誤。

有沒有辦法做到這一點?

+0

運行第一個查詢時得到的錯誤是什麼?配置單元中的每個子查詢都必須有別名。 –

回答

0
select t1.name 

from   tab1 t1 

     join (select  id 
          ,count(*) as cnt 
       from  tab2 
       group by id 
       order by cnt desc 
       limit  1 
       ) t2 

     on  t2.id = t1.id 
+0

出現以下錯誤。錯誤[10128]:尚未支持的UDAF「計數」位置 – Pragadeesh

+0

在內部選擇中,順序沒有意義。只需完全刪除它。 – Andrew

+1

@Andrew - 它有'極限' –