select distinct l1.num as consecutivenums
from logs as l1 
    left join logs as l2 on l1.id + 1 = l2.id
    left join logs as l3 on l1.id + 2 = l3.id
where l1.num = l2.num and l2.num = l3.num

join은 여러 번 사용할 수 있다.

 

(문제 출처 - https://leetcode.com/problemset/database/)

'섭섭의 공부 > SQL' 카테고리의 다른 글

[HackerRank] Weather Observation Station 6  (0) 2021.12.25
[HackerRank] Weather Observation Station 5  (0) 2021.12.25
[HackerRank] The Report  (0) 2021.12.24
[LeetCode] Department Highest Salary  (0) 2021.12.24
[HackerRank] Challenges  (0) 2021.12.23

+ Recent posts