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 |
+------------+----------+--------+
# Write your MySQL query statement below
select d.Name Department, e.Name Employee, e.Salary
from Employee e,Department d
where e.DepartmentId=d.Id
and (e.DepartmentId,e.Salary) in
(
select DepartmentId,max(Salary)
from Employee
group by DepartmentId
);

【SQL】184. Department Highest Salary的更多相关文章

  1. 【SQL】177. Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  2. 【SQL】176. Second Highest Salary

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  3. [LeetCode#184]Department Highest Salary

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

  4. 【SQL】185. Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  5. 184. Department Highest Salary

    问题描述 解决方案 select b.Name Department,a.Name Employee,a.Salary from ( select e1.Salary,e1.Name,e1.Depar ...

  6. [LeetCode] Department Highest Salary -- 数据库知识(mysql)

    184. Department Highest Salary The Employee table holds all employees. Every employee has an Id, a s ...

  7. 【sql】leetcode习题 (共 42 题)

    [175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column ...

  8. 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. +----+ ...

  9. 【SQL】关于无法附加文件的错误

    [SQL]关于无法附加文件的错误 1.错误信息如下: 2.估计是权限问题右击属性,把权限开一下 3.然后就附加成功了~~ ——————————————————————————————————————— ...

随机推荐

  1. debian下配置双核cpu

    ----------------------------文:jiqing(吉庆) http://hi.baidu.com/jiqing0925email: jiqingwu@gmail.comdate ...

  2. 20155323 2016-2017-2 《Java程序设计》第7周学习总结

    20155323 2016-2017-2 <Java程序设计>第7周学习总结 使用Lambda语法来代替匿名的内部类,代码不仅简洁,而且还可读. 时间的度量:GMT.UT.TAI.UTC. ...

  3. Python练习-time模块

    明天的明天的明天,雾草! # 编辑者:闫龙 #显示当前时间三天后是星期几? import time t = time.time()+((24*3600)*3) tl = time.localtime( ...

  4. Qt多线程编程中的对象线程与函数执行线程

    近来用Qt编写一段多线程的TcpSocket通信程序,被其中Qt中报的几个warning搞晕了,一会儿是说“Cannot create children for a parent that is in ...

  5. 【FCS NOI2018】福建省冬摸鱼笔记 day1

    省冬的第一天. 带了本子,笔,一本<算法导论>就去了.惊讶于为什么同学不带本子记笔记. 他们说:“都学过了.”,果然这才是巨神吧. 第一天:数论,讲师:zzx 前几页的课件挺水,瞎记了点笔 ...

  6. JDOM生成XML文档的一般方法

    由于DOM提供的生成XML的方法不够直观,而且要用到各种繁琐的注解,鉴于此可借助第三方库-----JDOM生成XML文档.具体操作方式如下: import java.io.FileOutputStre ...

  7. ip分片重组 ip_defrag

    在ip_local_deliver中,如果检测到是分片包,则需要进行分片重组: ip_local_deliver |-->ip_is_fragment //判断是否为分片包 |-->ip_ ...

  8. mybatis待研究

    1. mapper 中_parameter 的含义,是 参数? 为什么?

  9. ASP.NET MVC5 支持PUT 和DELETE

    Web.config <configuration> <system.webServer> <handlers> <remove name="Ext ...

  10. java基础34 泛型的使用

    本文知识点(目录): 1.泛型的好处    2.泛型在集合中的常见应用(这里只用String类型举例)    3.在泛型中是不能使用基本数据类型,如果需要使用基本数据类型,那么就使用基本数据类型对应的 ...