SQL/LeetCode

[LeetCode] 180. Consecutive Numbers

yeyeyep 2025. 2. 17. 17:19

 

 

[문제]

이미지를 누르면 문제 링크로 넘어갑니다

 

 

[MySQL]

SELECT DISTINCT num AS ConsecutiveNums
FROM (
    SELECT num
         , LEAD(num, 1) OVER (ORDER BY id) AS num_1_after
         , LEAD(num, 2) OVER (ORDER BY id) AS num_2_after
    FROM Logs) AS nums_list
WHERE num = num_1_after
  AND num_1_after = num_2_after