【发布时间】:2020-08-16 05:57:59
【问题描述】:
我正在使用以下 SELECT 语句计算加权移动平均线:
SELECT ts_g as ts, runningAccumulate(tpv) / runningAccumulate(tvol) as vwap
FROM
(
SELECT ts_g, sumState(pv) tpv, sumState(vol_per_price) tvol
FROM (
SELECT ts_g, close * vol_per_price as pv, sum(vol) as vol_per_price
FROM tablename_here
WHERE ts >= toDateTime64('2018-02-04 14:30:00.000000', 6, 'UTC')
AND ts < toDateTime64('2019-02-27 23:59:00.000000', 6, 'UTC')
GROUP BY toStartOfInterval(ts, INTERVAL 1 minute) AS ts_g, close
ORDER BY ts_g ASC, close ASC
)
GROUP BY ts_g
ORDER BY ts_g
)
产生正确的结果(下面的前十行):
┌──────────────────ts─┬──────vwap─┐
│ 2018-02-05 18:05:00 │ 2742.0000 │
│ 2018-02-05 21:54:00 │ 2706.3333 │
│ 2018-02-05 23:49:00 │ 2686.0000 │
│ 2018-02-05 23:51:00 │ 2675.8500 │
│ 2018-02-06 11:56:00 │ 2664.8750 │
│ 2018-02-06 14:34:00 │ 2660.6071 │
│ 2018-02-06 15:35:00 │ 2658.6562 │
│ 2018-02-07 16:25:00 │ 2667.4722 │
│ 2018-02-09 14:53:00 │ 2663.2250 │
│ 2018-02-16 13:23:00 │ 2671.6590 │
└─────────────────────┴───────────┘
我想选择该响应的子集,如下所示:
SELECT ts, vwap
FROM ( original query here )
WHERE ts >= toDateTime64('some start date', 6, 'UTC')
AND ts < toDateTime64('some end date', 6, 'UTC')
ORDER BY ts
但是,这总是返回0 rows in set,即使 WHERE 子句中的日期范围与原始日期范围相同或更宽。我做错了还是clickhouse中的错误?
版本:
ClickHouse server version 20.6.3.28 (official build).
ClickHouse client version 20.6.3.28 (official build).
【问题讨论】:
标签: sql where-clause clickhouse