使用 between 条件连接 ClickHouse 中的表
Join tables in ClickHouse with between condition
我发现ClickHouse中的join只支持等式。
但是我需要在 ClickHouse 中加入两个具有 'between' 条件的大表。
如何实现这个逻辑?
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;
遇到错误
Code: 403, e.displayText() = DB::Exception: Invalid expression for JOIN ON. Expected equals expression...
试试这个:
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
)
查看 中的一些 JOIN 细节。
我发现ClickHouse中的join只支持等式。 但是我需要在 ClickHouse 中加入两个具有 'between' 条件的大表。
如何实现这个逻辑?
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;
遇到错误
Code: 403, e.displayText() = DB::Exception: Invalid expression for JOIN ON. Expected equals expression...
试试这个:
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
)
查看