Employees Earning More Than Their Managers
The Employee
table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given the Employee
table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
+----------+
| Employee |
+----------+
| Joe |
+----------+
思路一:用exists
SELECT Name from Employee e1 where EXISTS (SELECT ID FROM Employee e2 where e1.ManagerId = e2.Id AND e1.Salary > e2.Salary);
自连接
SELECT e1.Name FROM Employee e1 LEFT JOIN Employee e2 ON e1.ManagerId = e2.Id WHERE e1.Salary > e2.Salary;
Employees Earning More Than Their Managers的更多相关文章
- [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- LeeCode(Database)-Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- Leetcode 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers
SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...
- 【SQL】181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- LeetCode - Employees Earning More Than Their Managers
Description: The Employee table holds all employees including their managers. Every employee has an ...
- 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- DataBase -- Employees Earning More Than Their Managers My Submissions Question
Question: The Employee table holds all employees including their managers. Every employee has an Id, ...
- LeetCode——Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
随机推荐
- Mac系统的launchd、守护进程daemon(2013笔记整理)
1. launchd Mac系统下通用的进程管理器,是Mac系统下非常重要的一个进程,一般来说该进程不允许直接以命令行的形式调用.只能通过其控制管理界面,launchctl来进行控制. launchd ...
- Matlab零碎知识
1.不定积分的求取 int syms x;%为自变量 f=x.^2; s=int(f,x); 其中显示辅助函数simple()和pretty()
- nodejs PK php全方位比较PHP的Node.js的优缺点
全方位比较PHP的Node.js的优缺点 http://www.techug.com/php-vs-node-js
- Java之网络编程UDP和TCP
注*部分转来的 第1章 网络通信协议 通过计算机网络可以使多台计算机实现连接,位于同一个网络中的计算机在进行连接和通信时需要遵守一定的规则,这就好比在道路中行驶的汽车一定要遵守交通规则一样.在计算机网 ...
- Lucene.net 搜索引擎的中文资料
以下是我找到的网上一些关于Lucene.net 搜索引擎的介绍资料 https://code.i-harness.com/zh-CN/tagged/lucene?page=5 http://jingp ...
- 关于js模板引擎template的使用记录
引言 有一天在群里有一个人发了这么一个图片 看到这个就会发现2个问题,一个是后期如果html结构改变了,这一大块都要重写.还有一个就是写的时候自己都看不清,很容易出错. 然后还有一个人写的清楚一点,但 ...
- EasyUI+MVC4实现后台管理系统一:登陆和进入后台界面
首先实现登陆: 未完待续...
- Leetcode 第136场周赛解题报告
周日的比赛的时候正在外面办事,没有参加.赛后看了下题目,几道题除了表面要考的内容,还是有些能发散扩展的地方. 做题目不是最终目的,通过做题发现知识盲区,去研究学习,才能不断提高. 理论和实际是有关系的 ...
- 微信小程序小结(2) ------ 自定义组件
在小程序中有模板跟组件的概念.但模板更多的用于内容的展示,更复杂的交互逻辑就没办法了.所以在小程序中也定义了一些组件来解决一些简单逻辑的功能. 但有时预定义的组件并不能满足我们的需求,这时就需要我们自 ...
- 在eclipse中打开文件所在的目录
eclipse中默认是不能直接打开文件所在的目录的,需要在文件中右键-->properties-->location,复制到资源管理器中才能打开文件所在的目录.这种方法很麻烦.这里介绍一种 ...