https://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
Table: Employee
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
+--------------+---------+
id is the primary key column for this table.
departmentId is a foreign key of the ID from the Department table.
Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
Table: Department
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the ID of a department and its name.
A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.
Write an SQL query to find the employees who are high earners in each of the departments.
Return the result table in any order.
The query result format is in the following example.
SELECT t.Department,
t.Employee,
t.Salary
FROM (
SELECT Department.name AS Department,
Employee.name AS Employee,
Employee.salary AS Salary,
DENSE_RANK() OVER (PARTITION BY Employee.departmentId ORDER BY Employee.salary DESC) AS dr
FROM Employee
INNER JOIN Department ON Employee.departmentId = Department.id
) t
WHERE t.dr <= 3
Consecutive Numbers(LeetCode) (0) | 2022.08.05 |
---|---|
The Report(HackerRank) (0) | 2022.08.05 |
challenges(HackerRank) (0) | 2022.08.05 |
Department Highest Salary(Leet Code) (0) | 2022.08.05 |
Delete Duplicate Emails(Leet Code) (0) | 2022.08.02 |
댓글 영역