SELECT a. NAME AS Department, g. NAME AS Employee, g.Salary FROM Department a INNER JOIN Employee g ON a.Id = g.DepartmentId LEFT JOIN ( SELECT e.DepartmentId, max(e.Salary) AS Salary FROM Employee e INNER JOIN ( SELECT c.DepartmentId, max(c.Salary) AS Salary FROM Employee c INNER JOIN ( SELECT DepartmentId, max(Salary) AS Salary FROM Employee GROUP BY DepartmentId ) b ON c.DepartmentId = b.DepartmentId WHERE c.Salary < b.Salary GROUP BY c.DepartmentId ) d ON e.DepartmentId = d.DepartmentId WHERE e.Salary < d.Salary GROUP BY e.DepartmentId ) f ON g.DepartmentId = f.DepartmentId WHERE f.DepartmentId IS NULL OR g.Salary >= f.Salary
Finally,I succeed!!! Happy to share my code.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.