The Employee table holds all employees. Every employee has an ID, a salary, and there are also a column for the department ID. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentID | +----+-------+--------+--------------+ | 1 | Joe | 70000 | 1 | | 2 | Henry | 80000 | 2 | | 3 | Sam | 60000 | 2 | | 4 | Max | 90000 | 1 | +----+-------+--------+--------------+ The Department table holds all departments of the company. +----+----------+ | Id | Name | +----+----------+ | 1 | IT | | 2 | Sales | +----+----------+ Write a SQL query to find employees who has the highest salary in each of the departments. For the above tables, Max have the highest salary in the IT department and Henry have the highest salary in the Sales depart ment. +------------+----------+--------+ | Department | Employee | Salary | +------------+----------+--------+ | IT | Max | 90000 | | Sales | Henry | 80000 | +------------+----------+--------+ Test instructions: Find out the highest wages in each department, if there are multiple maximum wages are output. 1, the highest wages for each department 2, the internal connection to determine which employee wages equals the highest wage select T.department,e.name as ' Employee ', e.salary from Employee e inner Jo In (select D.id as ' DepartmentID ', d.name as ' Department ', Max (e.salary) as ' Max ' from Employee e inner JOIN Department D on e.departmentid=d.id Group by D.name) T on E.departmentid=t.departmentid and Salary=max;
Department Highest Salary