influxDB | get elapsed time between last and first points

1.3k Views Asked by At

How to get difference between the first point in measurement and the last?

Example:

name: m1
time                ID ms
----                -- --
1573826041643021709 1  195
1573826041914872651 2  97
1573826042124354048 3  52
1573826042313151871 4  34
1573826042491637063 5  30

I need to get diff between 1573826041643021709 and 1573826042491637063

select sum(elapsed) from (select elapsed(ms) from m1) shows me expected result, but the way looks complicated and it seems something easier and more elegant should be.

1

There are 1 best solutions below

2
Steephen On

Find first and last point in measurement for the field 'ms' and calculate the difference between them.

 select first(ms) - last(ms) from m1;