[LeetCode] 180. Consecutive Numbers

2022. 6. 9. 23:05SQL

 

SELECT id AS ConsecutiveNums
FROM (
    SELECT id,
        num,
        LEAD(num,1) OVER (ORDER BY id) AS two_num,
        LEAD(num,2) OVER (ORDER BY id) AS three_num
    FROM Logs) sub
WHERE num=two_num AND two_num=three_num