我正在记录能源使用情况数据作为计数器,我希望将其显示为每天重置的累积图表,类似于asked here。
我可以生成累积值,如下所示:
img {
float: right;
margin:;//here is blank
以及每日价值:
SELECT mean("value") \
FROM "energy" \
WHERE $timeFilter \
GROUP BY time($__interval)
但是我不能减去它或在一个查询中得到它,因为GROUP BY时间是不同的。
(如何)在influxdb中可行?我已经看过INTEGRATE()了,但是还没有找到一种使它起作用的方法。
数据如下所示(示例限制为1天):
SELECT max("value") \
FROM "energy" \
WHERE $timeFilter \
GROUP BY time(1d)
答案 0 :(得分:1)
我found a solution,最后很简单:
SELECT kaifa-kaifa_fill as Energy FROM
(SELECT first(kaifa) as kaifa_fill from energyv2 WHERE $timeFilter group by time(1d) TZ('Europe/Amsterdam')),
(SELECT first(kaifa) as kaifa from energyv2 WHERE $timeFilter GROUP BY time($__interval))
fill(previous)
请注意,必须使用fill(上一个)来确保kaifa_fill和kaifa重叠。
示例数据:
time kaifa kaifa_fill kaifa_kaifa_fill
---- ----- ---------- ----------------
2019-08-03T00:00:00Z 179688195 179688195 0
2019-08-03T01:00:00Z 179746833 179688195 58638
2019-08-03T02:00:00Z 179803148 179688195 114953
2019-08-03T03:00:00Z 179859464 179688195 171269
2019-08-03T04:00:00Z 179914038 179688195 225843
2019-08-03T05:00:00Z 179967450 179688195 279255
2019-08-03T06:00:00Z 179905910 179688195 217715
2019-08-03T07:00:00Z 179847272 179688195 159077
2019-08-03T08:00:00Z 179698065 179688195 9870
2019-08-03T09:00:00Z 179378170 179688195 -310025
2019-08-03T10:00:00Z 179341013 179688195 -347182
2019-08-03T11:00:00Z 179126201 179688195 -561994
2019-08-03T12:00:00Z 179039116 179688195 -649079
2019-08-03T13:00:00Z 178935193 179688195 -753002
2019-08-03T14:00:00Z 178687870 179688195 -1000326
2019-08-03T15:00:00Z 178517762 179688195 -1170433
2019-08-03T16:00:00Z 178409776 179688195 -1278420
2019-08-03T17:00:00Z 178376102 179688195 -1312093
2019-08-03T18:00:00Z 178388875 179688195 -1299320
2019-08-03T19:00:00Z 178780181 179688195 -908015
2019-08-03T20:00:00Z 178928226 179688195 -759969
2019-08-03T21:00:00Z 179065241 179688195 -622954
2019-08-03T22:00:00Z 179183098 179688195 -505098
2019-08-03T23:00:00Z 179306179 179688195 -382016
2019-08-04T00:00:00Z 179306179 179370042 -63863
2019-08-04T00:00:00Z 179370042 179370042 0
2019-08-04T01:00:00Z 179417649 179370042 47607
2019-08-04T02:00:00Z 179464094 179370042 94053
2019-08-04T03:00:00Z 179509960 179370042 139918
2019-08-04T04:00:00Z 179591820 179370042 221779
2019-08-04T05:00:00Z 179872817 179370042 502775
2019-08-04T06:00:00Z 180056278 179370042 686236
2019-08-04T07:00:00Z 179929713 179370042 559671
2019-08-04T08:00:00Z 179514604 179370042 144562
2019-08-04T09:00:00Z 179053049 179370042 -316992
2019-08-04T10:00:00Z 178683225 179370042 -686817
2019-08-04T11:00:00Z 178078269 179370042 -1291773
2019-08-04T12:00:00Z 177650387 179370042 -1719654
2019-08-04T13:00:00Z 177281724 179370042 -2088317
2019-08-04T14:00:00Z 177041367 179370042 -2328674
2019-08-04T15:00:00Z 176807397 179370042 -2562645
2019-08-04T16:00:00Z 176737148 179370042 -2632894
2019-08-04T17:00:00Z 176677349 179370042 -2692693
2019-08-04T18:00:00Z 176690702 179370042 -2679340
2019-08-04T19:00:00Z 176734825 179370042 -2635216
2019-08-04T20:00:00Z 176810300 179370042 -2559742
2019-08-04T21:00:00Z 176866035 179370042 -2504007
2019-08-04T22:00:00Z 176914803 179370042 -2455239
2019-08-04T23:00:00Z 176965893 179370042 -2404149
2019-08-05T00:00:00Z 176965893 177016983 -51090
2019-08-05T00:00:00Z 177016983 177016983 0
示例图: