Reputation: 1249
Most common use for continuous query is to calculate average etc.
CREATE CONTINUOUS QUERY minnie ON world BEGIN SELECT min(mouse) INTO min_mouse FROM zoo GROUP BY time(30m) END
I have data points with increment values I am attempting to calculate the difference in value in every interval.
INSERT mydb value=4 1470101034546846145
INSERT mydb value=8 1470101042290558132
INSERT mydb value=10 1470101043594271416
I want to get 10 - 4 = 6 for example.
Is there a way to achieve this using continuous query?
Upvotes: 2
Views: 3102
Reputation: 2597
Your options are
DIFFERENCE()
for sequential differences. In you example, DIFFERENCE(mouse)
would give 8-4, 10-8, etc. This might be useful for you, but doesn't fit your description.SPREAD()
: seems to be what you're looking for, which is shorthand for MAX(mouse) - MIN(mouse)
on the interval. So something like: SELECT SPREAD(mouse) AS "mouse_range" INTO mouse_calcs FROM zoo GROUP BY time(30m)
, where mouse_range
and mouse_calcs
are names I picked with no special meaning.Upvotes: 1
Reputation: 305
Try using the new DIFFERENCE()
function in your query:
https://docs.influxdata.com/influxdb/v0.13/query_language/functions/#difference
SELECT DIFFERENCE(<function>(<field_key>)) FROM <measurement_name> WHERE <stuff> GROUP BY time(<time_interval>)
This is available since v0.13 I think.
Upvotes: 1