我试图在Druid / Superset中编写一个SQL查询,它执行一个' GROUP BY'对于来自同一表格的数据的两个不同时间间隔(让我们说最后7天和最后30天)并加入两个结果。例如,第一个GROUP BY的结果包含列' col1,col2,col3,freq1' (freq1是聚合产生的计数)。第二个结果包含列' col1,col2,col3,freq2'。我想得到以下输出:' col1,col2,col3,freq1,freq2'。问题是,德鲁伊并不完全支持连接。我试过这样的话:
WITH
interval1 AS
(
SELECT col1, col2, col3, COUNT(*) AS freq
FROM pv_sample
WHERE __time >= TIME_SHIFT(CURRENT_TIMESTAMP, 'P1D', -7)
AND __time <= CURRENT_TIMESTAMP
GROUP BY col1, col2, col3
LIMIT 10
),
interval2 AS
(
SELECT col1, col2, col3, COUNT(*) AS freq
FROM pv_sample
WHERE __time >= TIME_SHIFT(CURRENT_TIMESTAMP, 'P1D', -30)
AND __time <= CURRENT_TIMESTAMP
GROUP BY col1, col2, col3
LIMIT 10
)
SELECT i1.col1, i1.col2, i1.col3, i1.freq AS freq1, i2.freq AS freq2
FROM interval1 i1, interval2 i2
WHERE i1.col1 = i2.col1 AND
i1.col2 = i2.col2 AND
i1.col3 = i2.col3
结果是:未知异常(io.druid.java.util.common.ISE):无法构建查询计划:WITH interval1 AS(SELECT ...
有人可以给我一个提示,我的代码有什么问题,我怎么能解决我的问题呢?
祝你好运 马丁