题目链接:点击打开链接
题目大意:略。
解题思路:解决方案(1) 和 解决方案(2) 思路都是差不多的:先子查询查出每个部门的最高薪资,然后做下表关联拼接即可~区别无非在于子查询的关联上,前者用的是笛卡尔积,后者用的是 IN 语法(没想到 IN 还可以多个值同时去对齐吧)
AC 代码
--解决方案(1) SELECTd.NameDepartment, e.NameEmployee, e.SalaryFROMEmployeeeJOINDepartmentdONe.DepartmentId=d.Id, (SELECTMAX(Salary) Salary, DepartmentIdFROMEmployeeGROUPBYDepartmentId) rsWHERErs.Salary=e.SalaryANDrs.DepartmentId=e.DepartmentId--解决方案(2) SELECTDepartment.nameAS'Department', Employee.nameAS'Employee', SalaryFROMEmployeeJOINDepartmentONEmployee.DepartmentId=Department.IdWHERE (Employee.DepartmentId , Salary) IN ( SELECTDepartmentId, MAX(Salary) FROMEmployeeGROUPBYDepartmentId ) ;