leetcode SQL题目好好写一下
leetcode 184
部门工资最高的
# Write your MySQL query statement below SELECT e1.name as Employee, e1.salary as Salary, d.name as Department from employee e1 INNER join department d on e1.departmentId = d.id WHERE 1 >= ( SELECT COUNT(distinct (e2.salary)) from employee e2 WHERE e2.salary >= e1.salary and e2.departmentId = d.id ) ORDER BY d.name, e1.salary DESC ;
leetcode 185
部门工资最高的三个人
# Write your MySQL query statement below select d.Name Department ,e1.Name Employee,e1.Salary Salary from Employee e1 inner join Department d on e1.DepartmentId= d.Id where 3 >= ( select count(distinct(e2.Salary)) from Employee e2 where e2.Salary >=e1.Salary and e2.DepartmentId=d.Id ) order by d.Name,e1.Salary Desc;