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. L2,breakfast or lunch

    express: what a day多么糟糕的天气 I‘m coming to see you我将要来看你 what a lot of trouble he is causing他犯了多少错误啊 w ...

  2. 剑指offer 二叉搜索树后续遍历序列 判断

    最后一个元素是 根节点. 左子树的元素都小于根节点,右子树都大于根节点 然后递归判断 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  3. C# 经典入门15章-TextBoxControl

    第一步:设计界面如下:

  4. SQL Server 2008登录问题(错误 233和18456)解决方法

    今天使用 SQLSERVER2008 先遇到了233 错误,后又遇到了 18456 ,从网上找到了解决方法,具体如下: 问题一 : 已成功与服务器建立连接,但是在登录过程中发生错取.(provider ...

  5. Utils 工具 推送

    work_weipa_百度云推送 2014-09-05 17:55 7人阅读 评论(0) 收藏 举报 问题:怎么实现消息推送? 回答:下载sdk,根据文档操作即可 资料:http://develope ...

  6. Mac 生产力探究

    转载自:http://devtian.me/2015/04/15/about-my-productivity-tool-in-MacOSX/ ##密码管理器 1Password 1Password 是 ...

  7. Android程序两种退出的方法

    两种程序退出的方法: Context的finish()方法: android.os.Process的killProcess()方法:(当程序isRegistered()失败,说明程序被修改过,调用ki ...

  8. 解决BT5不能使用putty连接问题

    root@bt:~# cd /etc/sshroot@bt:/etc/ssh# sshd-generate Generating public/private rsa1 key pair.Your i ...

  9. 自行修改android.jar使其包含隐藏api

    1) 从指定版本的rom内获取到framework.jar 2) 解压framework.jar和android sdk内的android.jar 3) 将framework.jar解出来的东西拷到a ...

  10. Quartz定时调度

    测试类 import static org.quartz.JobBuilder.newJob; import static org.quartz.TriggerBuilder.newTrigger; ...