Search code examples
time-seriesinfluxdb

Influxdb - subtracting data from two subsequent timestamps


I want to subtract data from two subsequent timestamps from the same day but I haven' been able to find an exact way to do it.

         time             v1       v2      v3    
   02/05/18 23:59:39    76442   89105   79666
   02/05/18 23:59:51    76475   89142   79700
   03/05/18 0:00:03        32      36   34
   03/05/18 0:00:15        65      73   68


    time              p1   p2  p3 
  02/05/18 23:59:39   0    0   0
  02/05/18 23:59:51   33  37   34
  03/05/18 0:00:03    0    0   0
  03/05/18 0:00:15    33  37   34

Does the concept of cross joins in mysql apply to influx db as well or is there another method to do this in influx db ?


Solution

  • There are no joins in influxdb, but you can use difference(), derivative(), non_negative_derivative() aggregate functions in query.

    > INSERT myMetric value1=1
    > INSERT myMetric value1=10
    > select value1 from myMetric
    name: myMetric
    time                value1
    ----                ------
    1526032578114702408 1
    1526034352621423990 10
    > select difference(value1) from myMetric
    name: myMetric
    time                difference
    ----                ----------
    1526034352621423990 9
    > select derivative(value1,1s) from myMetric
    name: myMetric
    time                derivative
    ----                ----------
    1526034352621423990 0.005071832014237941