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 |
+----------+ 自连接
找出比其上司挣得更多的员工 MySQL(1686ms):
 SELECT e1.Name AS Employee
FROM Employee AS e1 , Employee AS e2
WHERE e1.ManagerId = e2.Id
AND e1.Salary > e2.Salary ;

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

  1. Leetcode 181. Employees Earning More Than Their Managers

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

  2. 【SQL】181. 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 不会分析的数据库复杂度

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

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

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

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

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

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

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

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

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

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

  9. LeetCode - Employees Earning More Than Their Managers

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

随机推荐

  1. Ubuntu安装CUDA9.0 + cuDNN

    本篇文章是基于安装CUDA 9.0的经验写,CUDA9.0目前支持Ubuntu16.04和Ubuntu17.04两个版本,如下图所示(最下面的安装方式我们选择第一个,即runfile方式): 下载链接 ...

  2. std::string::find() 和 std::string::npos

    npos是一个常数,用来表示不存在的位置,string::npos代表字符串到头了结束了.   int idx = str.find("abc");if (idx == strin ...

  3. Ruby环境搭建

    刚接触Ruby,发现Ruby真心强大,搞了那么久的Java了,已经被Java的繁琐的语法整的无语透顶了,尤其的Java异常,设计出来就是个失败呀!Ruby目前更新到了2.x了,社区也很活跃,开发效率和 ...

  4. run (牛客多校第二场)计数DP

    链接:https://www.nowcoder.com/acm/contest/140/A来源:牛客网 题目描述 White Cloud is exercising in the playground ...

  5. Android JUnit test

    Android单元测试步骤 1.修改AndroidManifest.xml文件. 添加instrumentation节点.其中name是固定值,targetPackage为需要测试的类所在的包.如:  ...

  6. 如何更有效使用 Rational AppScan 扫描大型网站,第 2 部分: 案例分析

    使用 AppScan 进行扫描 针对大型网站的扫描,我们按照戴明环 PDCA 的方法论来进行规划和讨论,建议 AppScan 使用步骤:计划(Plan).执行(Do).检查(check).分析(Ana ...

  7. sql service 事务与锁

    了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂,不能保证数据的安全正确读写. 死锁: ...

  8. Spring Boot应用中的异常处理

    在普通的单线程程序中,捕获异常只需要通过try ... catch ... finally ...代码块就可以了.那么,在并发情况下,比如在父线程中启动了子线程,如何正确捕获子线程中的异常,从而进行相 ...

  9. C11简洁之道:函数绑定

    1.  可调用对象 在C++中,有“可调用对象”这么个概念,那么什么是调用对象呢?有哪些情况?我们来看看: 函数指针: 具有operator()成员函数的类对象(仿函数): 可以被转换为函数指针的类对 ...

  10. dp优化-四边形不等式(模板题:合并石子)

    学习博客:https://blog.csdn.net/noiau/article/details/72514812 看了好久,这里整理一下证明 方程形式:dp(i,j)=min(dp(i,k)+dp( ...