184. 部门工资最高的员工
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;