Im between cherry

LeetCode | MySQL | 185. Department Top Three Salaries 본문

데이터분석/practice_query

LeetCode | MySQL | 185. Department Top Three Salaries

meal 2020. 9. 9. 09:51

leetcode.com/problems/department-top-three-salaries/

 

Department Top Three Salaries - LeetCode

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.

leetcode.com

/* RANK(), DENSE_RANK() */
SELECT t.Employee,
       t.Department,
        t.Salary
FROM(
    SELECT department.name AS department
        , employee.name AS employee
        , employee.salary AS salary
        , DENSE_RANK() OVER (PARTITION BY departmentid ORDER BY salary DESC) AS dr
    FROM employee
        INNER JOIN department ON employee.DepartmentId = department.id
)t
WHERE t.dr <= 3

 

Comments