Department Highest Salary
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 |
+------------+----------+--------+
SELECT d.Name AS Department, e.Name AS Employee, t.Salary AS Salary FROM Employee e join
(Select DepartmentId, MAX(Salary) AS Salary from Employee group BY departmentId) t
USING (DepartmentId,Salary)
JOIN Department d
on t.DepartmentId = d.Id;
Department Highest Salary的更多相关文章
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- [LeetCode] Department Highest Salary -- 数据库知识(mysql)
184. Department Highest Salary The Employee table holds all employees. Every employee has an Id, a s ...
- [LeetCode] Department Highest Salary 系里最高薪水
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode DB: Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- 【SQL】184. Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [LeetCode#184]Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode——Department Highest Salary(花式使用IN以及GROUP BY)
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode - Department Highest Salary
题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息 有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group ...
随机推荐
- PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )
1, pop自定义 public class SelectPicPopupWindow extends PopupWindow { private Button btn_take_photo, btn ...
- [51nod1043]幸运号码
题意:1个长度为2N的数,如果左边N个数的和 = 右边N个数的和,那么就是一个幸运号码. 例如:99.1230.123312是幸运号码. 给出一个N,求长度为2N的幸运号码的数量.由于数量很大,输出数 ...
- [凸包]Triangles
https://nanti.jisuanke.com/t/15429 题目大意:给出平面内$n$个整数坐标点,保证无三点共线.可以进行若干次连线,每次选择一个点对连接线段,但是任意两条线段都不得在给定 ...
- sell01 环境搭建、编写持久层并进行测试
1 环境配置 JDK 1.8 MAVEN 3.5 MYSQL 5.7 VirtualBox 5.1 2 搭建MYSQL环境 下载 VM 和 虚拟镜像文件 虚拟镜像文件:点击前往 技巧01:安装完vir ...
- 杭电acm 1033题
Problem Description For products that are wrapped in small packings it is necessary that the sheet o ...
- Hadoop的namenode和secondnamenode分开部署在不同服务器
一.系统环境: Hadoop 0.20.2.JDK 1.6.Linux操作系统 二.使用背景 网上关于Hadoop的集群配置,很多情况下,都是把namenode和secondnamenode部署在 ...
- ibatis分页的两种方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- 第三周作业-课本&&视频学习
<网络攻防技术与实践>第三周作业 Part I 寻找自己留在互联网上的足迹并消除隐私 1.1 google/baidu搜索自己的qq号 搜索结果如图,搜到的有用信息其实就是图上这么几条,能 ...
- Ubuntu 安装 samba 实现文件共享和source insight 阅读uboot
环境:win10 + 虚拟机Ubuntu 12.04 一. samba的安装: # sudo apt-get install samba # sudo apt-get install smbfs 二. ...
- 使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.
从Log4j切换到Log4j2,没有打包之前日志输出正常,但是打包后总是提示下面内容: 错误一: ERROR StatusLogger Log4j2 could not find a logging ...