LeetCode184——部门工资最高的员工

版权声明:我的GitHub:https://github.com/617076674。真诚求星! https://blog.csdn.net/qq_41231926/article/details/86569320

我的LeetCode代码仓:https://github.com/617076674/LeetCode

原题链接:https://leetcode-cn.com/problems/department-highest-salary/description/

题目描述:

知识点:JOIN子句、IN子句、GROUP BY子句及聚合函数MAX()

思路:用JOIN子句内连接查询两个表,用GROUP子句分组并用聚合函数MAX()获得各个部门的最高工资

SQL语句:

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

LeetCode解题报告:

猜你喜欢

转载自blog.csdn.net/qq_41231926/article/details/86569320
今日推荐