184. 部门工资最高的员工

文章目录

  • 题意
  • 思路
  • 代码

题意

题目链接
查出每个部门最高工资

思路

子查询+group by

代码

select 
    b.name as Department,
    a.name as Employee,
    salary
from 
    Employee as a
left join
    Department as b
on
    a.departmentId = b.id
where
    (a.departmentId, salary) 
    in
        (
            select 
                departmentId, Max(salary)
            from
                Employee
            group by    
                departmentId 
        )

你可能感兴趣的:(leetcode)