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:

SELECT t FROM temps
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:
https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/built-in/transformations/difference/
https://v2.docs.influxdata.com/v2.0/query-data/flux/window-aggregate/

Or you could use this function too perhaps:
https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/built-in/transformations/timeshift/

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