185. Department Top Three Salaries

select d.Name Department, e1.Name Employee, e1.Salary
from Employee e1 
join Department d
on e1.DepartmentId = d.Id
where 3 > (select count(distinct(e2.Salary)) 
                  from Employee e2 
                  where e2.Salary > e1.Salary 
                  and e1.DepartmentId = e2.DepartmentId
                  );

  

posted @ 2017-10-25 04:41  Weiyu Wang  阅读(103)  评论(0编辑  收藏  举报