第一种情况:普通情况
第二种情况:
第三种情况:
结果:
select
t1.Name as Employee,t1.Salary as Salary,t2.Name as Department
from
Employee t1 left join Department t2 on t1.DepartmentId=t2.Id
where (t1.DepartmentId,t1.Salary) in (select t4.DepartmentId, max(t4.salary) as s from Employee t4 group by t4.DepartmentId) and t2.Id is not null