LeetCode 181-185
2020-11-16 本文已影响0人
1nvad3r
181. 超过经理收入的员工
select a.Name as 'Employee'
from Employee a inner join Employee b
on a.ManagerId = b.Id
where a.Salary > b.Salary
182. 查找重复的电子邮箱
select email from Person
group by Email having count(Email) >1
183. 从不订购的客户
select Name as 'Customers'
from Customers where
id not in (select CustomerId from Orders )
184. 部门工资最高的员工
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
where (e.departmentId ,e.salary) in
(select departmentId,max(salary) from Employee
group by departmentId)
185. 部门工资前三高的所有员工
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
where 3 > (
select count(distinct e2.salary) from Employee e2
where e2.salary > e.salary and e.Departmentid = e2.Departmentid
)