Consecutive Numbers(Window함수)
문제
코드
Window함수 사용
MS SQL Server/Oracle
SELECT DISTINCT L.NUM AS ConsecutiveNums
FROM (
SELECT NUM
, LEAD(NUM, 1) OVER (ORDER BY ID) AS NEXT
, LEAD(NUM, 2) OVER (ORDER BY ID) AS AFTERNEXT
FROM LOGS
) L
WHERE L.NUM = L.NEXT AND L.NUM = L.AFTERNEXT
Window함수 미사용
Oracle
SELECT DISTINCT L.NUM AS ConsecutiveNums
FROM LOGS L
INNER JOIN LOGS F ON L.ID + 1 = F.ID
INNER JOIN LOGS S ON L.ID + 2 = S.ID
WHERE L.NUM = F.NUM
AND L.NUM = S.NUM
수행결과