LeetCode MySQL 184. 部门工资最高的员工
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL 184. 部门工资最高的员工
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 題目
- 2. 解題
1. 題目
Employee 表包含所有員工信息,每個員工有其對應的 Id, salary 和 department Id。
+----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000 | 1 | | 2 | Henry | 80000 | 2 | | 3 | Sam | 60000 | 2 | | 4 | Max | 90000 | 1 | +----+-------+--------+--------------+Department 表包含公司所有部門的信息。
+----+----------+ | Id | Name | +----+----------+ | 1 | IT | | 2 | Sales | +----+----------+編寫一個 SQL 查詢,找出每個部門工資最高的員工。
例如,根據上述給定的表格,Max 在 IT 部門有最高工資,Henry 在 Sales 部門有最高工資。
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/department-highest-salary
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
2. 解題
# Write your MySQL query statement below select d.Name Department, e.Name Employee, e.Salary from Employee e, Department d where e.DepartmentId = d.Idand (e.DepartmentId, Salary) in(select DepartmentId, max(Salary) Salaryfrom Employee group by DepartmentId)我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關注我的公眾號(Michael阿明),一起加油、一起學習進步!
總結
以上是生活随笔為你收集整理的LeetCode MySQL 184. 部门工资最高的员工的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 931. 下降路径最小
- 下一篇: LeetCode MySQL 1112.