[英]hive left outer join with between condition
I know we can't do un-equal joins in hive. 我知道我们不能在蜂巢中进行不平等的联接。 I need to convert below query in to hive (hql). 我需要将下面的查询转换为蜂巢(hql)。 Any suggestions/workaround's would be appreciated. 任何建议/解决方法将不胜感激。
Both table_A and table_B dose not have primary key. table_A和table_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
I think you can fix this (to a close approximation) by using a where
clause. 我认为您可以使用where
子句解决此问题(近似)。 It should read: 它应显示为:
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
)
There are some subtle differences between having the condition in the where
clause versus the on
clause, but they probably will not affect your query. 在where
子句和on
子句中具有条件之间存在一些细微的差异,但是它们可能不会影响您的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.