hive left outer join with between条件

db2dz4w8  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(557)

我知道我们不能在Hive里做不相等的连接。我需要将下面的查询转换为配置单元(hql)。如有任何建议/解决方法,将不胜感激。
表a和表b都没有主键。

SELECT * 
FROM table_A f
LEFT OUTER JOIN table_B dom1
 ON dom1.country = f.issuing_office_country
AND dom1.ulr_source = 'Loss'
AND dom1.valuation_class = f.dsp_level_join
AND dom1.year_type = 'UW'
AND f.undwrtr_yr_prd_fy_mnth BETWEEN dom1.start_year_month AND dom1.end_year_month

LEFT OUTER JOIN table_B dom2
 ON dom2.country = f.issuing_office_country
AND dom2.ulr_source = 'Short'
AND dom2.valuation_class = f.div_level_join 
AND dom2.year_type = 'UW'
AND f.undwrtr_yr_prd_fy_mnth BETWEEN dom2.start_year_month AND dom2.end_year_month
mnemlml8

mnemlml81#

我想你可以通过使用 where 条款。应改为:

where (f.undwrtr_yr_prd_fy_mnth BETWEEN dom1.start_year_month AND dom1.end_year_month or
       dom1.valuation_class is null
      ) and
      (f.undwrtr_yr_prd_fy_mnth BETWEEN dom2.start_year_month AND dom2.end_year_month or
       dom2.valuation_class is null
      )

在这种情况下有一些微妙的区别 where 子句与 on 子句,但它们可能不会影响您的查询。

相关问题