Data is in a table in this format:
id value timestamp
1 112 1234561
1 111 1234562
2 111 1234563
2 111 1234564
1 111 1234565
1 111 1234566
1 112 1234567
2 111 1234568
How to write SQL (Ansi-99) query that would do following:
Give me ID with Starting and Ending timestamp for all unique IDs that have 3 consecutive values=111?
In this case - output of query should be:
1, 1234562
1, 1234566
2, 1234563
2, 1234568
(or:
1, 1234562, 1234566
2, 1234563, 1234568
)
Timestamp is always ordered (from lower to higher).
Not looking to work for specific database - just a SQL logic in general (but if it will help - let's say it is MySQL).
Thanks!