Problem
Write a SQL query to find all numbers that appear at least three times consecutively.
1 |
|
For example, given the above Logs
table, 1
is the only number that appears consecutively for at least three times.
1 |
|
Explanation
-
To have 3 consecutive numbers, we can have 3 Logs table.
-
We will select distince number and make sure first table’s id equal to second table’s id minus 1, and second table’s id equal to third table’s id minus 1, and all three table’s number are equal.
Solution
1 |
|