문제
정답
요점은 ROW_NUMBER
를 거꾸로 만들어서 비교한다는 아이디어이다.
SELECT id, company, salary
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY company ORDER BY salary, id) AS idx_up,
ROW_NUMBER() OVER (PARTITION BY company ORDER BY salary DESC, id DESC) AS idx_down
FROM Employee
) AS temp
WHERE idx_up BETWEEN idx_down - 1 AND idx_down + 1
ORDER BY company, salary