โข
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
๋ณต์ฌ