clickhouse中带between条件的sql连接表

oyxsuwqo  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(2200)

我发现加入clickhouse只支持相等的表达式。但我需要在clickhouse中加入两个“中间”条件的大表。
如何实现这个逻辑?

select a.*, b.name
from a
join b
  on a.id = b.id
  and a.start_dt between b.start_dt and b.end_dt;

出现错误
代码:403,e.displaytext()=db::exception:join on的表达式无效。应为equals表达式。。。

zvokhttg

zvokhttg1#

试试这个:

select a.*, b_name
from (
  select a.*, b.name AS b_name, b.start_dt AS b_start_dt, b.end_dt AS b_end_dt
  from a join b using id
  where a.start_dt between b_start_dt and b_end_dt
  )

查看clickhouse join with condition中的一些连接细节。

相关问题