LeetCode-184. 部门工资最高的员工(中等)

在这里插入图片描述
在这里插入图片描述
题目来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/department-highest-salary
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

本人思路:
方法一:
– 1、先找到每个部门工资最高的员工,输出员工和最高工资,构成临时表temp
– 2、将Employee表与temp表内连接,输出所有工资大于等max_salary的员工

select temp.department as Department, e1.Name as employee ,e1.salary
from Employee as e1
inner join 
(
select d.id as id ,d.Name as department,max(salary) as max_salary
from Employee as e inner join Department as d
on e.DepartmentId =d.id 
group by d.id 
)temp
on e1.DepartmentId = temp.id
where e1.salary >= temp.max_salary

方法二:
1、将temp表放在where条件中,直接进行判断

select D.Name as Department,E.Name as Employee,E.Salary as Salary
from Employee E
join Department D
on E.DepartmentId = D.Id
where (E.Salary,E.DepartmentId) in 
(
    select max(Salary) as Salary,DepartmentId as Department
    from Employee
    group by DepartmentId
)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值