ClickHouse无法识别外部表别名

Outer table alias is not recognized in ClickHouse

提问人:Muhammad Ahmad Mujtaba 提问时间:8/25/2023 更新时间:8/25/2023 访问量:95

问:

我在ClickHouse中有一个名为kafkadata的时间序列表,我想找出与传入数据时间戳相关的过去数据中特定范围匹配的行。

例如,在过去的记录中,查找与范围 (-X, +X) 匹配的所有记录,其中 X 是以秒为单位的正数;与传入记录。

为此,我构建了以下查询,但是,CH 似乎无法识别嵌套查询中的外部表别名。

select t2.`event`, t2.`timestamp`, t2.`ID`,
    (
        select grouparray(t1.`event`) as ge--, grouparray(t1.`ID`) as gid,
        from default.`kafkadata` as t1
        where t1.`timestamp` <= date_sub(second, 3, t2.`timestamp`)
            and t1.`timestamp` >= date_add(SECOND, 3, t2.`timestamp`)
        group by t1.`event`, t1.`ID`
    ) as ge
from default.`kafkadata` as t2
group by t2.`event`, t2.`timestamp`, t2.`ID`;

来自ClickHouse的错误

SQL Error [47] [07000]: Code: 47. DB::Exception: Missing columns: 't2.timestamp' while processing query: 'SELECT grouparray(event) AS ge FROM default.kafkadata AS t1 WHERE (timestamp <= (t2.timestamp - toIntervalSecond(3))) AND (timestamp >= (t2.timestamp + toIntervalSecond(3))) GROUP BY event, ID', required columns: 'timestamp' 't2.timestamp' 'ID' 'event', maybe you meant: 'timestamp', 'ID' or 'event': While processing (SELECT grouparray(t1.event) AS ge FROM default.kafkadata AS t1 WHERE (t1.timestamp <= (t2.timestamp - toIntervalSecond(3))) AND (t1.timestamp >= (t2.timestamp + toIntervalSecond(3))) GROUP BY t1.event, t1.ID) AS ge. (UNKNOWN_IDENTIFIER) (version 23.6.2.18 (official build))¶, server ClickHouseNode [uri=http://localhost:8123/default, options={use_server_time_zone=false,use_time_zone=false,session_timeout=1000000}]@-1581460642

任何人都可以在这里指导,这里出了什么问题,什么是替代选择?

SQL 嵌套 ClickHouse

评论

0赞 nbk 8/25/2023
ClickHouse 不支持相关子查询,计划于 2023 年发布,但这一年几乎是板上钉钉的
0赞 nbk 8/25/2023
您的子查询看起来不对,但您可以加入相关的子查询并访问列
0赞 Rich Raposa 8/26/2023
您是否尝试过使用 CTE(通用表表达式)?clickhouse.com/docs/en/sql-reference/statements/select/with

答: 暂无答案