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
'기존학습자료 > leetcode, hackerrank' 카테고리의 다른 글
Leetcode 185 - Department Top Three Salaries (0) | 2023.06.25 |
---|---|
Leetcode 184 - Department Highest Salary (0) | 2023.06.25 |
해커랭크 - Type of Triangle (CASE) (0) | 2023.06.25 |
해커랭크 - Symmetric Pairs (UNION) (0) | 2023.06.25 |
해커랭크 - INNER JOIN, LEFT JOIN (0) | 2023.06.25 |