```sql
select Department.name as Department,Employee.name as Employee,Salary
from Employee
join Department
on Employee.DepartmentId=Department.Id where(DepartmentId,Salary)
in
(
select DepartmentId, max(Salary)
from Employee
group by DepartmentId
)
多表的联结又分为以下几种类型:
左联结(left join),联结结果保留左表的全部数据
右联结(right join),联结结果保留右表的全部数据
内联结(inner join),取两表的公共数据
高级版本
select Department.name as Department,
Employee.name as Employee,
Employee.Salary as Salary
from Employee
join Department
on Employee.DepartmentId=Department.Id
where (
select count(distinct Salary) <=3
from Employee as E1
where Employee.DepartmentId=E1.DepartmentId
and
Employee.Salary<=E1.Salary
)
order by DepartmentId,Salary desc