Fetch consecutive values


#1

I have a measurement:

time, state
t0 1
t1 1
t2 0
t3 0
t4 1
t5 0
t6 1
t7 1
t8 0

I wish to write a query which shall return me the start and end timestamp of the states between 2 consecutive 1s. i.e t2 and t5

Something like:

Select last(*) from measurement where state = 1 and state -1 = 1