Участник:Froyg/top 3 salaries

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/department-top-three-salaries/submissions/

MS SQL

SELECT d.Name AS 'Department' , e.Name AS 'Employee', e.Salary AS 'Salary' FROM Employee e
 
INNER JOIN
 
Department d ON e.DepartmentId = d.Id
 
LEFT JOIN Employee AS e2 ON e.DepartmentId = e2.DepartmentId AND e.Salary <= e2.Salary
 
GROUP BY d.Name, e.Name, e.Salary, e.DepartmentId
 
HAVING(COUNT(DISTINCT e2.Salary) <= 3)
 
ORDER BY e.DepartmentId, e.Salary DESC