LeetCode - Department Highest Salary
题目大概的意思是选出每个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的更多相关文章
- [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 ...
- 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 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 DB: 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 ...
- [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] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- [LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
随机推荐
- VC++中动态链接库的显示加载和隐式加载的区别
两种方法对于你的程序调用动态库时没有任何区别,只是你在编程时,步骤是不一样的.显式调用麻烦了点,但可以没有相应的lib库:隐式调用,使用起来比较 简单,有函数的声明(头文件.h)就可以了,但必须有li ...
- 透明遮罩图层VS高斯模糊滤镜 效果分析
前端流行布局中最常见的弹出图层有popup, 对话框, tooltip等, 他们都使用了新的图层,但是实现办法各不相同, 有 的是通过半通明的黑白图层实现的, 有的是通过滤镜实现的, 我们来研究一下两 ...
- R语言设置write.table()输出的文件格式
write.table(),是保存数据为文件的函数. > xiaohuqingdan <- c(3900088702, 3900072499,3900021029) > xiaohu ...
- C++多线程环境下注意共享资源的释放顺序
比如我现在写一个多线程下载程序,包含DownloadTask.HttpDownload两个类. class DownloadTask { //省略n行代码 public: int m_threads; ...
- MySQL索引覆盖
什么是“索引覆盖”? 简单来的说,就是让查询的字段(包括where子句中的字段),都是索引字段.索引覆盖的好处是什么?好处是极大的.极大的.极大的提高查询的效率!重要的说三遍! 特别说明: 1.whe ...
- [转]anchorPoint 锚点解析
转自:http://blog.csdn.net/cjopengler/article/details/7045638 anchor point 究竟是怎么回事? 之所以造成不容易理解的是因为我们平时看 ...
- C++ 获取当前时间
#include <time.h> #include <stdio.h> int main( void ) { time_t t = time(0); char ...
- 原型模式(prototype pattern)---------创造型模式
原型模式的缺点: 1.需要为每一个类配备一个克隆方法,而且该克隆方法位于一个类的内部,当对已有的类进行改造时,需要修改源代码,违背了开闭原则(open-closed discipline) 2.在实现 ...
- 解决导入protobuf源代码Unity报错的问题
将源代码导入Assets目录后, unity引擎会出现以下报错: 解决办法: 在 unity项目Assets目录中创建smcs.rsp文件,内容为-unsafe,其作用为可编译不安全代码. 然 ...
- mysqldump: command not found
原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件.首先得知道mysql命 ...