Leetcode - 185. Department Top Three Salaries

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

정답

SELECT Department.name AS Department, Employee.name as Employee, Employee.salary AS Salary
FROM (
        SELECT *, DENSE_RANK() OVER (PARTITION BY departmentId ORDER BY salary DESC) AS n
        FROM Employee
) AS Employee
JOIN Department ON Employee.departmentId = Department.id
WHERE n <= 3