Can I use a fetched variable to define further queries? If so how?

I have a database of weather and my heating system data.
I’m trying to make a query that would return historical heating data for a certain outside temperature. I have this working with a pre-selected temperature in the query, but how do I reference the current temperature in the historical query?

So I would like to do this:

get mean of historical heating data where temp = currentTemp.

I couldn’t make this work.
Is there a way of storing variables in Grafana? and use them? So i could store $currentTemp and use that in the query.

My historical query looks like this now:
SELECT mean("extfram") FROM "modbus" WHERE utemp<-25 AND $timeFilter GROUP BY time($__interval) fill(null)

So it is the “utemp<-25” that I would like to replace with the current fetched temperature from the database.

Help! :slight_smile:

Solved it - I found the variables field :slight_smile: So i made a variable for current temperature to use in the query.

Sorry :slight_smile:

Follow up question though, is there any other way to update this variable than refresh the page? It would be cool If It would update as often as the dashboard updates.