I want to select all the rows from table where date different between two row is 4 or less and stop as soon as condition don’t match ie diff > 4 in descending order i.e.(from bottom)
caution: once condition is > 4 it will not match further it simply
stops
i.e it will have to select 5,6,7,8,9

I tried using “HAVING“, but its slow on big data
Thank you all in advance to helping figure it out.
You can use user-defined variables to track the previous
updated_atvalue (in my example below, in@t) then calculate from that whether the record is desired based on whether the previous record was desired (@b) and, if so, the difference between that last date and the current one:See it on sqlfiddle.