SELECT distinct t1.num as ConsecutiveNums
FROM logs t1
JOIN logs t2 ON t1.id + 1 = t2.id
JOIN logs t3 ON t1.id + 2 = t3.id
WHERE t1.num = t2.num and t2.num = t3.num
The join table looks like
id1 num1, id2 num2, id3 num3, which makes the id 2 and id 3 and id 1 in the same row, and can be compared.
Below is a better solution from peers, this solution is amazing!
select distinct Num as ConsecutiveNums
from Logs
where (Id + 1, Num) in (select * from Logs) and (Id + 2, Num) in (select * from Logs)
Question SQL solution
The join table looks like id1 num1, id2 num2, id3 num3, which makes the id 2 and id 3 and id 1 in the same row, and can be compared.
Below is a better solution from peers, this solution is amazing!