【问题标题】:Join tables in ClickHouse with between condition在 ClickHouse 中使用 between 条件连接表
【发布时间】:2021-04-27 14:57:14
【问题描述】:

我发现 ClickHouse 中的 join 只支持相等的表达式。 但我需要在 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 的表达式无效。预期等于表达式...

【问题讨论】:

  • 为 between 条件尝试 WHERE 子句。或者使用 ">= 和

标签: sql clickhouse


【解决方案1】:

试试这个:

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 中的一些 JOIN 细节。

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 2019-08-18
    相关资源
    最近更新 更多