Leetcode

LeetCode 180. Consecutive Numbers [MySql]

치킨먹고싶어요 2022. 6. 3. 17:23

 

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

 

Consecutive Numbers - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

select distinct l1.num as ConsecutiveNums
from logs l1, logs l2, logs l3
where l1.id + 1 = l2.id and l2.id + 1 = l3.id and l1.num = l2.num and l2.num = l3.num

풀이:

from에서 logs를 3번 부른 후, id와 num을 검사하여 출력하면 됩니다.

그리고 num이 중복될 수 있으니 distinct를 해 주어야 합니다.