184.部门工资最高的员工
链接:184.部门工资最高的员工
难度:Medium
标签:数据库
简介:查找出每个部门中薪资最高的员工。
题解 1 - sql
- 编辑时间:2024-10-16
 - 执行用时:1327ms
 - 编程语言:sql
 - 解法介绍:利用子查询查找比当前薪水大的同部门的人为0的人
 
select 
    d1.name as Department,
    e1.name as Employee,
    e1.salary as Salary
from 
    Employee e1 left join Department d1 on e1.departmentId = d1.id
where 0 = (
    select count(*)
    from Employee e2
    where 
        e2.salary > e1.salary and
        e1.departmentId = e2.departmentId
)