1

我需要使用特定的旧版本 HIVE,它会阻止我在 GTE 或 LTE 条件下加入 2 个表。例如什么是等价的

select *
from table1 as t1
left join table2 as t2
on t1.id = t2.id
  and (t1.date >= t2.date and t1.date <= t2.date+7) -- i can no longer do this condition

什么是替代查询?

4

1 回答 1

2

另一种方法是将条件的 GTE/LTE 部分移至where将在加入后作为过滤器应用的子句:

select *
  from table1 as t1
       left join table2 as t2 on t1.id = t2.id
 where (t1.date >= t2.date and t1.date <= date_add(t2.date,7)) 
       or t2.id is null
于 2017-11-20T19:03:43.497 回答