[英]Hive - Join based on condition
表 gr 有 2 個字段,名為 ph 和 flag
表 ep 有一個名為 ph 的字段
現在我需要檢查 ep 中 ph>20 的計數,如果 flag <> 'Y'
我寫了兩個單獨的查詢,需要知道如何加入它們
select ph,count(*) from ep
group by ph
having count(*)>20
這個結果應該用 gr 表檢查
使用內部連接 ON ep.ph = gr.ph and gr.flag<> 'Y'
:
select gr.ph, gr.cnt
from
(select ph, flag, count(*) cnt
from gr
group by ph, flag
) gr
inner join
( select ph,count(*) from ep
group by ph
having count(*)>20
) ep ON ep.ph = gr.ph and gr.flag<> 'Y'
where gr.cnt!=0 --find where count is not 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.