Leetcode: Department Highest Salary
来源:互联网 发布:网络冗余设计 编辑:程序博客网 时间:2024/06/07 03:33
Question
The Employee table holds all employees. Every employee has an Id, a salary, and there is 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 have the highest salary in each of the departments. For the above tables, Max has the highest salary in the IT department and Henry has the highest salary in the Sales department.
+————+———-+——–+
| Department | Employee | Salary |
+————+———-+——–+
| IT | Max | 90000 |
| Sales | Henry | 80000 |
+————+———-+——–+
Other′s Solution
# Write your MySQL query statement belowselect d2.Name, e2.Name, temp.maxsfrom (select max(e.Salary) as maxs, d.id as didFrom Employee e, Department dwhere e.DepartmentId=d.Idgroup by d.Id) as temp, Employee e2, Department d2where temp.did=e2.DepartmentId and temp.maxs=e2.Salary and temp.did=d2.Id
- LeetCode:Department Highest Salary
- Leetcode: Department Highest Salary
- LeetCode Department Highest Salary
- [Leetcode]Department Highest Salary
- Leetcode: Department Highest Salary
- [LeetCode][Database]Department Highest Salary
- Database LeetCode Department Highest Salary
- leetcode.184. Department Highest Salary
- Leetcode 184. Department Highest Salary
- Leetcode 184. Department Highest Salary
- [LeetCode] Department Highest & Top 3 Salary - SQL
- [LeetCode]Department Highest Salary,解题报告
- 【leetcode Database】184. Department Highest Salary
- 【LeetCode】Department Highest Salary && Department Top Three Salaries
- Department Highest Salary
- Department Highest Salary
- Department Highest Salary
- Department Highest Salary
- javascript中call()和apply()
- MEIZU MX4连接不上adb
- 黑马程序员-【集合框架】
- KI码
- javaScript document对象详解
- Leetcode: Department Highest Salary
- DecimalFormat 数据格式化类的使用小结
- ios多语言本地化
- 怎样在spring官网上下载spring的zip包
- Android JNI开发指南
- android开发工具下载
- 浩易南:网络赚钱是怎么炼成的?
- redis源码分析(8)——replication
- 企业QQ 增加在线交谈链接