Hive: work around for non equi left join

前端 未结 4 1730
耶瑟儿~
耶瑟儿~ 2020-12-18 09:57

Hive does not support non equi joins: The common work around is to move the join condition to the where clause, which work fine when you want an inner join. but what about a

4条回答
  •  盖世英雄少女心
    2020-12-18 10:45

    Not sure if you can avoid using a double join:

    SELECT * 
    FROM OrderLineItem li 
    LEFT OUTER JOIN  (
      SELECT p.*
      FROM ProductPrice p
      JOIN OrderLineItem li 
      ON p.ProductID=li.ProductID 
      WHERE OrderDate BETWEEN StartDate AND EndDate ) p
    ON p.ProductId = li.ProductID
    WHERE StartDate IS NULL OR 
      OrderDate BETWEEN StartDate AND EndDate;
    

    This way if there is a match and StartDate is not null, there has to be a valid start/end date match.

提交回复
热议问题