기존학습자료/leetcode, hackerrank
Leetcode 181 - Consecutive Numbers
gooreumsea
2023. 6. 25. 05:58
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