Find all spreads greater than X in a series

I have a series of temperature values with minute resolution and want to find all instances in which which the temperature dropped sharply overnight (say, over 8h) by more than X degrees.

I could do this on the client side by iterating over each temperature currTemp in the series,

SELECT t AS currTemp FROM temps

storing the current time as currTime, then running another InfluxDB querry looking ahead up to 8 hours:

WHERE t < currTemp - X
AND time >= currTime AND time < currTime + 8h

But that will run a ton of queries (24 * 60 per day).

Is there a way to have InfluxDB do all the processing, perhaps with subqueries?

Hello @dandv,
You can use flux and tasks to do something like this more easily in 2.x. using these functions:

Or you could use this function too perhaps:

Then you could join the data currTemp and t and calculate the difference.