码迷,mamicode.com
首页 > 其他好文 > 详细

184. 部门工资最高的员工

时间:2020-03-18 14:00:50      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:query   you   缩减   problem   需要   esc   tco   href   bsp   

 

184. 部门工资最高的员工

需要注意的几个点,inner join可以缩减成join,取的是两个表的交集

in关键词,找的是当前所要找的数值是否在指定的范围之中

# Write your MySQL query statement below
select d.Name as Department,
       e.Name as Employee,
       e.Salary 
       from Employee e inner join Department d on e.DepartmentId = d.Id
       where (DepartmentId, e.Salary)
       in
       (select DepartmentId, max(Salary) from Employee group by DepartmentId);    

 

这个是有问题的版本,暂时还不知道怎么改,只是提示group by使用错误

# Write your MySQL query statement below 
select d.Name as Department, e1.Name as Employee,
max(e1.Salary) as Salary from Employee e1, Employee e2,
Department d where e1.Salary >= max(e2.Salary)
and
e1.DepartmentId = e2.DepartmentId group by e1.Id order by e1.Salary desc;

 

184. 部门工资最高的员工

标签:query   you   缩减   problem   需要   esc   tco   href   bsp   

原文地址:https://www.cnblogs.com/letlifestop/p/12516614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!