Calculate total time a variable has not changed

I am using the community version of Grafana.
I have live data flowing into Grafana from Clickhouse. I want to record how long(time) the value of a key has not changed.
Currently, my data into the database only when the value changes. For each key, I want to calculate the total time in a day that the value has remained the same.

Status = 1 recorded at 9am
Status = 0 recorded at 3pm
Status = 1 at 5pm

Total Status =1 in 2hr day = 13hrs

Has anyone created a SQL query or transformation in Grafana to capture a similar logic?