我有一个关于Influxdb的查询,例如:
SELECT last("Shop1.balance")+last("Shop2.balance")+last("Shop2.balance") + last("Shop2.balance") FROM "balances" WHERE $timeFilter GROUP BY time($__interval) fill(previous)
我收到graphana所有商店的总余额。它工作正常,直到我添加一个带有新数据的新商店:历史中某个时间间隔的新商店余额可以为空,整个计算值将为空。我无法重新组织我的数据库,但可能是我可以更改我的查询以接收日期,其中空间隔将被视为总和为零。
答案 0 :(得分:5)
这就像你问过的那样有效:
SELECT last("Shop1.balance") + last("Shop2.balance") + last("Shop3.balance)
FROM "balances"
WHERE $timeFilter
GROUP BY time($__interval) fill(0)
<强>演示强>
select last(balance1) as last_balance_1, last(balance2) as last_balance_2
from balance
where time > '2018-03-07T10:44:14.0000000Z' and time < '2018-03-07T10:44:52.0000000Z'
group by time(7s)
结果:
name: balance
time last_balance_1 last_balance_2
---- -------------- --------------
2018-03-07T10:44:13Z 1 2
2018-03-07T10:44:20Z 2 3
2018-03-07T10:44:27Z 4
2018-03-07T10:44:34Z 5 6
2018-03-07T10:44:41Z 7
2018-03-07T10:44:48Z 8 9
select last(balance1) as last_balance_1, last(balance2) as last_balance_2
from balance
where time > '2018-03-07T10:44:14.0000000Z' and time < '2018-03-07T10:44:52.0000000Z'
group by time(7s) fill(0)
结果:
name: balance
time last_balance_1 last_balance_2
---- -------------- --------------
2018-03-07T10:44:13Z 1 2
2018-03-07T10:44:20Z 2 3
2018-03-07T10:44:27Z 4 0
2018-03-07T10:44:34Z 5 6
2018-03-07T10:44:41Z 7 0
2018-03-07T10:44:48Z 8 9