【问题标题】:Sum of field with where condition of this field - Influxdb具有该字段的 where 条件的字段总和 - Influxdb
【发布时间】:2019-05-16 07:08:36
【问题描述】:

我想得到result_code 的总和,其中result_code=0

我发现没有 sum 的查询给了我结果,但添加了聚合 sum() 然后我得到 0 作为结果。

对于那些想要了解用例的人: 我使用电报 ping 一些内部 IP 地址来检查它的可用性(每 10 秒 ping 一次,超时 5 秒),我想每天获得它的正常运行时间 (result_code=0)。

我尝试更改 sum 函数中的字段,但效果不佳。

SELECT sum("result_code") FROM "ping" WHERE ("url" = 'MyUrl') AND time >= 1557957600000ms and result_code=0

name: ping
time                sum
----                ---
1557957600000000000 0
name: ping
time                result_code
----                -----------
1557988031000000000 0
1557988040000000000 0
...

在我的示例中,我希望有

name: ping
time                sum
----                ---
1557957600000000000 2

【问题讨论】:

  • 零和为零 - 你期望得到什么?看起来您需要count(result_code) - 而不是sum()。此外,您在查询中使用了没有 group by time(1d) 的聚合函数。
  • 我的意思是 count 而不是 sum 感谢您指出这一点:使用group by time(1d) 给我2行(可能是时区的问题......)
  • 纠正我使用的时区问题:GROUP BY time(1d) , deviceId TZ('Europe/Paris')

标签: sum influxdb influxql


【解决方案1】:

听起来您想要COUNT,而不是零值集合的SUM

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多