기존학습자료/leetcode, hackerrank
Leetcode 180 - Consecutive Numbers
gooreumsea
2023. 6. 24. 20:04
Consecutive Numbers
https://leetcode.com/problems/consecutive-numbers/
# 최소 3번이상 연속적으로 나타나는 숫자 찾기
# 순서는 상관없음
SELECT DISTINCT l.num AS ConsecutiveNums -- 중복제거
FROM logs AS l
INNER JOIN logs AS l_next ON l.id + 1 = l_next.id
INNER JOIN logs AS l_next2 ON l.id + 2 = l_next2.id
# three times consecutively
WHERE l.num = l_next.num AND l_next.num = l_next2.num