https://leetcode.com/problems/consecutive-numbers/

-- Use Window function

-- *LEAD,  *LAG



SELECT DISTINCT l.NUM AS ConsecutiveNums
     SELECT NUM
          , LEAD(NUM,1) OVER (ORDER BY id) AS next
          , LEAD(NUM,2) OVER (ORDER BY id ) AS afternext

     FROM logs
 )l
 WHERE l.Num=next AND l.next=l.afternext

+ Recent posts