InfluxDb连续查询排除零

时间:2017-09-03 18:01:56

标签: influxdb

我尝试在InfluxDb中创建连续查询,以将测量数据下采样为每小时平均值。我可以通过下面的连续查询来做到这一点。

CREATE CONTINUOUS QUERY "cq_test_1h" ON "db-name"
BEGIN
    SELECT mean("value") AS "mean_value"
    INTO "downsampled"."downsampled_measurement"
    FROM "autogen"."measurement"
    GROUP BY time(1h)
END

但我也希望如果每小时平均值等于零,则排除结果;所以downsampled_measurement系列不包含任何零值。我可以创建一个(嵌套的)查询来执行我想要的操作,但我不知道如何将其转换为连续查询。

SELECT mean_value
FROM
    (SELECT mean(value) AS mean_value
    FROM "measurement"
    WHERE time<now()
    GROUP BY time(1h))
WHERE mean_value>0

上面的查询有效,但要使其成为连续查询,需要在GROUP BY子句中使用聚合器WHERE子句和持续时间参数:

SELECT mean(mean_value)
FROM
    (SELECT mean(value) AS mean_value FROM "db-name"."autogen"."measurement"
    WHERE time<now()
    GROUP BY time(1h))
WHERE mean_value>0 AND time<now()
GROUP BY time(1h)

但是,此查询不再返回任何值。如何进行排除零的连续查询?

0 个答案:

没有答案