Description:
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.
The Department table holds all departments of the company.
Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).
Code:
先从Employee表中找工资最高的
select Department.Name as Department, Employee.Name as Employee, Salary as Salary
from Employee, Department
where Employee.DepartmentId = Department.Id and
Employee.Salary = (select max(Salary) from Employee where Employee.DepartmentId = Department.Id);