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的更多相关文章

  1. [LeetCode] Employees Earning More Than Their Managers 员工挣得比经理多

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  2. LeeCode(Database)-Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  3. Leetcode 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  4. [SQL]LeetCode181. 超过经理收入的员工 | Employees Earning More Than Their Managers

    SQL架构 Create table If Not Exists Employee (Id ), Salary int, ManagerId int) Truncate table Employee ...

  5. 【SQL】181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  6. LeetCode - Employees Earning More Than Their Managers

    Description: The Employee table holds all employees including their managers. Every employee has an ...

  7. 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

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

  9. LeetCode——Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

随机推荐

  1. IIS7.0(虚拟机)发布MVC5程序出现Http403错误的解决方法.

    近来,用MVC5开发自己的一个小网站.网上租用了一个小空间(虚拟主机),可选.net版本为2.0 3.0 3.5 4.0 ,上传网站 后发现是403错误.不能访问. 经与技术人员联系,把虚拟机更换到高 ...

  2. java数据库连接模板代码通用收集

    package org.lxh.dbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLE ...

  3. 使用DOS指修改文件名

    需求:将文件名中的特殊字符#和~去掉 文件夹路径如下: 开始->运行->在对话框中输入字母“cmd”,进入dos模式 输入命令行“cd c:\test”然后回车,再输入命令行“dir /b ...

  4. 20169219《linux内核原理与分析》第六周作业

    网易云课堂学习 1.intel x86 CPU有四种不同的执行级别0-3,linux只使用了其中的0级和3级分贝来表示内核态和用户态. 2.一般来说在linux中,地址空间是一个显著的标志:0xc00 ...

  5. 20169219 linux内核原理与分析第二周作业

    "linux内核分析"的第一讲主要讲了计算机的体系结构,和各寄存器之间对数据的处理过程. 通用寄存器 AX:累加器 BX:基地址寄存器 CX:计数寄存器 DX:数据寄存器 BP:堆 ...

  6. 2、Jquery_事件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. 在 windows 下搭建 IDEA + Spark 连接 Hive 的环境

    为了开发测试方便,想直接在 IDEA 里运行 Spark 程序,可以连接 Hive,需不是打好包后,放到集群上去运行.主要配置工作如下: 1. 把集群环境中的 hive-core.xml, hdfs- ...

  8. spring cloud微服务三:Eureka服务治理之注册服务提供者及服务的发现和消费

    当服务注册中心成功建立以后,就需要有服务的注册和消费,否则这个服务注册中心就没有了存在的意义,而实际上,一个简单的服务注册也是非常简单的,仅仅需要实现四部曲就好. 首先,还是建立一个基本的spring ...

  9. thinkphp5.1页面页面模板及参数配置

    success和error跳转的模板在thinkphp/tpl/dispatch_jump.tpl 配置参数在thinkphp\library\traits\controller\jump.php文件 ...

  10. thinkphp5引入百度编辑器

    在ThinkPHP的模板(html文件)中引入Ueditor  下载ueditor解压至public/static目录 在需要的页面引入js文件 <script type="text/ ...