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

思路:考虑同一个table Employee的两个copy e1 和 e2。Where 里面可以用AND。在一个table中根据一些条件选出一部分内容,如果这个条件牵扯到table里的其他row,那么往往使用select from table的多个copy。

# Write your MySQL query statement below
select e1.Name as Employee
from Employee as e1, Employee as e2
where e1.Salary > e2.Salary and e1.ManagerId=e2.Id)

Leetcode 181. Employees Earning More Than Their Managers的更多相关文章

  1. leetcode 181 Employees Earning More Than Their Managers 不会分析的数据库复杂度

    https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ 老师上课没分析这些的复杂度, ...

  2. LeetCode 181. Employees Earning More Than Their Managers (超过经理收入的员工)

    题目标签: 题目给了我们一个 员工表,包括经理.员工会有经理的id. 这里可以重复 利用两次 表格,表格a, 表格b,当a 员工的经理id  等于 b员工时候,在从中找到员工工资大于经理的.具体看co ...

  3. [LeetCode] 181. Employees Earning More Than Their Managers_Easy tag: SQL

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

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

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

  5. 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 SQL:Employees Earning More Than Their Managers

    # Write your MySQL query statement below SELECT a.Name FROM Employee AS a INNER JOIN Employee AS b O ...

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

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

  8. LeetCode - Employees Earning More Than Their Managers

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

  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. JavaScript基础教程

    功能介绍: (1)数据验证 弹出提示的对话框,产生判断的效果. (2)气泡提示窗口 右下角等等一类的窗口 (3)产生新窗口 (4)无边框窗口背景变灰,也是可以节约系统资源的

  2. 自定义solr的search UI

    solr使用apache的velocity来定义UI,在solr的search ui的基础上更改即可,主要改\example\solr\collection1\conf\velocity里的文件. 详 ...

  3. 关于mysql 删除数据后物理空间未释放(转载)

    转自 关于mysql 删除数据后物理空间未释放(转载) - NETDATA - 博客园http://www.cnblogs.com/shawnloong/archive/2013/02/07/2908 ...

  4. Android 自定义 SpinnerButton(转)

    Android 自定义 SpinnerButton 模仿Android4.0的Spinner Button写的一个MySpinnerButton.这样在1.6~4.0.4版本都可以实现这种下拉框的效果 ...

  5. [转]JSON详解

    阅读目录 JSON的两种结构 认识JSON字符串 在JS中如何使用JSON 在.NET中如何使用JSON 总结 JSON的全称是”JavaScript Object Notation”,意思是Java ...

  6. expected: file:///

    [java] java.lang.IllegalArgumentException: Wrong FS: hdfs://192.168.190.128:9000/user/hadoop/output/ ...

  7. Divisor Summation_

    Divisor Summation Problem Description Give a natural number n (1 <= n <= 500000), please tell ...

  8. linux下提示bash:command not found

    新安装的linux系统,如果进行精简安装可能会出现bash:command not found 的提示,大家在安装的时候可以选择默认安装basic的组件,一般即可.到时候可以再升级.   如果新装的系 ...

  9. c# 添加了按钮双击事件后,再删除掉代码会提示错误

    有两种方法:.清空属性窗口中的双击事件(doubleclick )右边的内容: .单击“发生错误”提示窗口的“否”后,再双击错误列表里的错误项,此时编辑窗口跳转为xx.Designer.cs,然后注释 ...

  10. 基于Spring的异步系统实现方案

    一般的实现方案 发送异步消息所使用的工具类: import java.util.Date; import javax.jms.Destination; import javax.jms.JMSExce ...