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. ArrayList遍历的同时删除--- 删除还是用迭代器的比较好,其它的都会有问题.

    http://javag.iteye.com/blog/403097 ArrayList遍历的同时删除-- 删除还是用迭代器的比较好,其它的都会有问题.     博客分类: 随笔 Javathread ...

  2. 解决 Oracle 11g 不能导出空表的问题

    --解决 Oracle 11g 不能导出空表的问题 --执行下面语句,查询数据库中的空表,同时产生分配空间.把生成的结果复制出来并执行. select 'alter table '||table_na ...

  3. hdu_2546_饭卡(01背包)

    题目连接:hdu_2546_饭卡 题意:中文,不解释 题解:先拿5元来买最贵的,最后就是一个01背包,这里也算用到贪心的思想 #include<bits/stdc++.h> #define ...

  4. Android开发之如何保证Service不被杀掉(broadcast+system/app)

    序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台运行,不管用户作出什么操作,都要保证service不被kill,这可真是一个难题.参考了现今各种定制版的系统和安全厂商牛虻 ...

  5. Android利用canvas画各种图形 及Paint用法 .

    引自:http://blog.csdn.net/carlfan/article/details/8139984 1.首先说一下canvas类: Class Overview The Canvas cl ...

  6. PAT1011

    With the 2010 FIFA World Cup running, 随着2010世界杯的举行 football fans the world over were becoming increa ...

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

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

  8. tset

    test fsdfs jsjf sdfsdfsdfsdf sfs fsfsfs test112 sdfs sdfsdf sdfs sf af s sdf sadfasdfsa asfasf sdfsa ...

  9. JS中判定问题

    今天项目遇到一个很奇怪的问题,具体问题不好说明简化下,有如下一个方法: function editStu(index, rowData) { if (index == "") { ...

  10. NodeJs与ActionScript的GET和POST通讯

    今天项目遇到一个小问题,做了个小功能,向服务端发送GET请求,但是服务端解析数据是时候报语法错误,如下: make Request data error:SyntaxError: Error #113 ...