Search

Consecutive Numbers

โ€ข
join์„ ์ด์šฉํ•œ ํ’€์ด
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 WHERE l.Num = l_next.Num AND l.Num = l_next2.Num ;
SQL
๋ณต์‚ฌ
โ€ข
์„œ๋ธŒ์ฟผ๋ฆฌ + ์œˆ๋„์šฐ ํ•จ์ˆ˜(LEAD, LAG)
# Write your MySQL query statement below SELECT DISTINCT t.Num AS ConsecutiveNums FROM (SELECT Num, LEAD(num, 1) OVER (ORDER BY id) AS next, LEAD(num, 2) OVER (ORDER BY id) AS next2 FROM Logs) AS t WHERE t.Num = t.next and t.Num = t.next2 ;
SQL
๋ณต์‚ฌ