您的位置:首页 > 其它

部门工资最高的员工

2019-04-15 21:27 176 查看

思路

1 此题分为两个步骤,一是寻找每组内的最高薪水,而是按照同指标对两表进行连接
2 此题借鉴了我之前的一个博文select套娃
以下为我的代码,在Heidi SQL中运行成功,但是在LeetCode中出现问题

select
department.name as deparment ,
employee.name as employee,
salary  from employee,department
where salary in (select
max(salary) as max_salary
from employee
group by departmentid)
and employee.departmentid=department.id

下面贴上评论中运行成功的代码源代码出处

select
d.Name as Department,
e.Name as Employee,
e.Salary
from
Employee e,Department d
where
e.DepartmentId=d.id
and
(e.Salary,e.DepartmentId) in (select max(Salary),DepartmentId from Employee group by DepartmentId);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐