InfluxDB获取更改列表

时间:2019-02-11 22:21:57

标签: influxdb

我想得到如下结果:

name           from_value      to_value            at 
tag A          10              15                  2019-02-11 16:00
tag B          1               2                   2019-02-11 16:00
tag A          15              20                  2019-02-11 16:05
tag B          2               3                   2019-02-11 16:05
tag A          20              25                  2019-02-11 16:10
tag B          3               4                   2019-02-11 16:10

基本上是“ from_value”列(先前值当前点)和“ to_value”列(当前值当前点)。

要仅选择当前点值,我要做:

SELECT value FROM data WHERE "name"='tag A'

如果我还要选择以前的值怎么办?

SELECT prev(value) AS "from_value", value AS "to_value" FROM data WHERE "name"='tag A'

我可以执行上述操作吗?还是需要每次为每个新点始终保存以前的值?

1 个答案:

答案 0 :(得分:1)

通过group by time,您可以使用last()difference()函数来获取每个时间间隔的值更改。

SELECT LAST(value)-DIFFERENCE(LAST(value)) as FromValue, LAST(value) as ToValue
FROM demo where time > 1549983975150000000 
GROUP BY time(10ms),tagA FILL(none)
name: demo
tags: tagA=1
time                FromValue ToValue
----                --------- -------
1549984410470000000           10
1549984421820000000 10        15
1549984431180000000 15        17
1549984436350000000 17        10
1549984753810000000 10        10
SELECT * FROM demo
name: demo
time                tagA value
----                ---- -----
1549984410475859753 1     10
1549984421827992234 1     15
1549984431180379398 1     17
1549984436356232522 1     10
1549984753817094214 1     10