The highest employee in LeetCode184 department (with experience and precautions)

SELECT Department.Name AS Department,Employee.Name AS Employee,Employee.Salary AS Salary 
FROM Employee INNER JOIN Department ON Employee.DepartmentId=Department.Id 
WHERE (Salary,DepartmentId) IN 
(SELECT MAX(Salary),DepartmentId FROM Employee  GROUP BY DepartmentId);

1. The point of this question is that the subquery IN can check multiple, just use parentheses.
(This should be a feature of the new version of sql, the book still talks about sub-queries that can only check one attribute)
2. The sub-table should also be enclosed in parentheses, otherwise an error will be reported.
3. The statement used in GROUP BY operates on data that has been divided into groups.
(I did not consider the use of sub-tables at the beginning, directly in the group by salary = MAX (salary)
so that there is only one employee with the highest salary).

Guess you like

Origin blog.csdn.net/m0_45311187/article/details/111300184