You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ClickHouse使用any inner join按日期关联两表语法报错求助

ClickHouse 关联查询语法报错排查

报错根因

  • JOIN修饰符顺序不符合ClickHouse语法规范:ClickHouse中ANY/ALL/SEMI这类连接修饰符必须放在连接类型(INNER/LEFT/RIGHT等)之后,原SQL写的any inner join顺序颠倒,导致语法解析失败。
  • 冗余括号干扰解析:FROM后对两个关联子查询额外包裹的多余括号,也是触发语法报错的原因之一。

修正后SQL

select 
    t1.event_date,
    t1.attraction_hash_cnt,
    t2.feid_cnt
from 
    (select 
        event_date, 
        uniq(attraction_hash) as attraction_hash_cnt
    from table_1
    where event_date >= toDate('2021-07-13') - 30
        and event_date <= toDate('2021-10-13')
        and trans_type in ('initial', 'trial')
    group by event_date) t1
inner any join
    (select 
        event_date, 
        uniq(feid) as feid_cnt
    from table_2
    where event_date >= toDate('2021-07-13') - 30
        and event_date <= toDate('2021-10-13')
    group by event_date) t2
using event_date

额外说明

由于你的两个子查询都是按event_date分组,每个日期只会返回一条统计结果,ANY修饰符其实没有实际作用,直接使用普通inner join替换inner any join也可以正常执行,结果完全一致。

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 10:45:00