在gte或lte条件下执行左连接的替代方法是什么?

2exbekwf  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(289)

我被要求使用一个特定的旧版本的配置单元,它阻止我加入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

什么是对此的替代查询?

irtuqstp

irtuqstp1#

另一种方法是将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

相关问题