+------------+----------+--------+
| Department | Employee | Salary |
+------------+----------+--------+
| IT | Max | 90000 |
| IT | Jim | 90000 |
| Sales | Henry | 80000 |
+------------+----------+--------+
解释:
Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。
select Department, Employee, Salary from(select Department.name Department, Employee.name Employee, Salary,rank() over (partitionby DepartmentId order by Salary desc) rkfrom Employee inner join Department on Employee.DepartmentId = Department.Id) twhere rk =1
where () in () 法
SELECT d.Name AS Department, e.Name AS Employee, e.Salary AS SalaryFROM Employee e, Department dWHERE e.DepartmentId = d.Id AND (d.Id,e.Salary) IN (SELECT DepartmentId, MAX(Salary) FROM Employee GROUP BY DepartmentId)