Assume I have the following table:
data_point (creation_datetime DATETIME PRIMARY KEY,
data_point INTEGER);
I am looking for an SQL query that would not only tell me if the most recent entry has a data_point value of X, but how many consecutive rows after it also have X as a value.
For instance, assuming the following data:
creation_datetime data_point
2012-10-31 12:00:00 0
2012-10-31 11:55:00 0
2012-10-31 11:50:00 0
2012-10-31 11:45:00 2
2012-10-31 11:40:00 0
If i had X=0, the number I would want back here would be 3, because the most recent value matches X, and the next 2 rows also match it.
I don’t have any ID column or anything. I could add one if need be, but I’d like to avoid it.
Counts the number of records after the last record that was not your desired value.