题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息

有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group by后面的属性,另一种是聚集函数。

2)在选取最大Salary时必须使用e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId两个条件,要不然会有重复。

基于这些考虑可以使用派生表查询来找出最大Salary,然后与Department表做自然连接。(最后的升序还是降序无所谓)

select dep.Name as Department, pans.Name as Employee,
pans.Salary as Salary
from Department dep, (
select e1.* from
Employee e1, (select DepartmentId, max(Salary) as Salary
from Employee group by DepartmentId) e2
where e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId
) pans
where dep.Id=pans.DepartmentId
order by pans.Salary desc;

LeetCode - Department Highest Salary的更多相关文章

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

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

  2. [LeetCode] Department Highest Salary 系里最高薪水

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

  3. 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 ...

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

  5. LeetCode DB: Department Highest Salary

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

  6. [LeetCode#184]Department Highest Salary

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

  7. [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary

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

  8. [LeetCode] Nth Highest Salary 第N高薪水

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

  9. [LeetCode] Second Highest Salary 第二高薪水

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

随机推荐

  1. [usb/uart]内核添加USB转串口驱动支持

    转自:http://blog.csdn.net/gatieme/article/details/49491325 目录 1. 问题 2. 驱动源码 3. 内核配置 4. 编译内核和模块驱动 5. 加载 ...

  2. 【 Linux 】单台服务器上并发TCP连接数

    单台服务器上并发TCP连接数    问题:一台服务器到底能够支持多少TCP并发连接呢? 1. 文件描述符限制:    对于服务器来说,每一个TCP连接都要占用一个文件描述符,一旦文件描述符使用完,新的 ...

  3. 测试markdown编辑器

    标题1 标题2 +++ 第一件事 +++ 第二件事 +++ 第三件事 |head|头|头栏| |body|body|body|

  4. SecureCRT工具

    技巧收集: 文本文件内容 复制该行内容yy,p粘贴 2+yy复制两行 dd 删除该行 文件内容搜索 非编辑状态/+查找内容 查找指定行 :+行号

  5. e686. 显示打印窗口

    The print dialog allows the user to change the default printer settings such as the default printer, ...

  6. [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30512   Accep ...

  7. 一键部署MongoDB集群Windows版

    由于周末在家手头没有虚拟机,所以在windows下单机完毕部署要求,并编写bat执行脚本. 1.创建配置文件及相关文件夹 总的启动脚本例如以下(startmc.bat): rem m1 start m ...

  8. openal 基础知识4

    二函数 1. buffer函数 void alGenBuffers(ALsizei n /* buffer数*/, ALuint * buffers /* buffer ID数组*/); void a ...

  9. eclipse安装spring tool suite插件

    在实际项目开发时,如果我们创建了一个spring文件,其实也就是个xml文件,如果没有集成spring的开发工具,创建的就是一个单纯的xml文件.安装spring插件以后创建spring配置文件会方便 ...

  10. 感谢各位亲们的大力支持,免费的HTML5学习课程《HTML5网页开发实例具体解释》连载已经结束了!

    感谢各位亲们的大力支持,免费的HTML5学习课程<HTML5网页开发实例具体解释>连载已经结束了.  有兴趣的读者能够看我的博客,也能够看以下的链接逐个学习: 当里个当.免费的HTML5连 ...