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. ab测试 uwsgi遇到的问题

    1 请求并发数目较大时,接收到的数目小于发送的数目 1.1 描述:uwsgi正常返回302跳转 ab -n 5000 -c 250 -g test.log "192.168.50.20:90 ...

  2. SQL Server 日志传送[转载]

    http://jimshu.blog.51cto.com/3171847/590413 SQL Server 2012 日志传送 一.准备: 数据库为完全恢复模式,并事先做一次完全备份. 共享一个文件 ...

  3. Android面试经验2

    1,android如何更换主题: 2,如何设计软件: 3,代码中用到那些设计模式: 4,c++和java有那些不同: 一,指针: 二,多重继承: 三,数据类型和类: 四,自动内存管理: 五,操作符重载 ...

  4. android点滴之HandlerThread的用法

    转载请注明出处:http://blog.csdn.net/lskshz/article/details/25364909 一.介绍 HandlerThread继承自Thread,当线程开启时,也就是它 ...

  5. mysql建库

    CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE DATABASE 的语法: CRE ...

  6. C#入门经典第八章面向对象编程简介-1

    面向对象编程(Object-Oriented Programming,OOP)技术 本章中的OPP实际上是.NET OOP,这里讲的一些技术不能应用于其他OOP环境.

  7. 关于tomcat启动没有进行编译或者编译报错的问题

    关于tomcat 的问题 如果项目没有编译 解决方案:1: 把项目刷新一下 然后Clean一下,之后等待右下角编译完成100%2: 有可能tomcat conf 里的配置文件的错误 进入查看下3: 如 ...

  8. call_grant_exec.sql

    set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee                 = & ...

  9. 环境:win7+ie8 IE8的F12不起作用,原因如下:

    1.先按下F12 2.再按下CTL+P,此时调试框将出现在屏幕下方. 3.再次点击CTL+P 4.此时在任务栏上的到IE8的图标,将会看到调试框,右击最大化,此时调试框是最大化状态. 5.然后再慢慢的 ...

  10. 使用Spring框架的好处(转帖)

    http://blog.csdn.net/cynhafa/article/details/6205361 在SSH框假中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为 ...