Question:

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

Analysis:

Employee表格包含公司里所有的员工,包括他们的经理。每个员工都有一个员工ID和一个经理ID。

给出Employee表格,写一个SQL语句,找出工资比他的经理还高的员工。例如在上面的例子中,只有Joe满足该情况。

最后给出什么则select后面接什么,如果遇到比较的,则应该选择使用两个表格。

Answer:

select e1.Name from Employee e1, Employee e2
where e2.Id = e1.ManagerId and e1.Salary > e2.Salary
 

DataBase -- Employees Earning More Than Their Managers My Submissions Question的更多相关文章

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

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

  2. [LeetCode] 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

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

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

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

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

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

  7. 181. Employees Earning More Than Their Managers

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

  8. Employees Earning More Than Their Managers

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

  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. (第02节)集成Sping框架

    通过第一节创建好的Web项目,接下来就是集成Spring框架 首先让我们看下创建好的Web项目的基本结构 其中,Java跟test是我自己创的,然后就是一般的webapp文件,和pom配置文件,要在w ...

  2. Hello,移动WEB—px,dp,dpr像素基础

    问题点1:iphone5分辨率:640 * 1136 dp,为什么chrome浏览器F12中显示的320 *568??         iPhone5 分辨率640 * 1136指的是物理像素,而实际 ...

  3. 介绍几个PHP 自带的加密解密函数

    PHP 自带的加密解密函数 目前经常使用的加密函数有:md5(), sha1(), crypt(), base64_encode(), urlencode() . 其中 md5(), sha1(), ...

  4. Java学习笔记十一:Java中的方法

    Java中的方法 一:什么是方法: 所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 学过C语言或者其他语言的应该都知道函数这个东西,在Java中,其实方法就是函数,只不过叫法不同,在 ...

  5. Python爬虫爬取百度翻译之数据提取方法json

    工具:Python 3.6.5.PyCharm开发工具.Windows 10 操作系统 说明:本例为实现输入中文翻译为英文的小程序,适合Python爬虫的初学者一起学习,感兴趣的可以做英文翻译为中文的 ...

  6. 【Leetcode】Jewels and Stones

    Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...

  7. debounce、throttle、requestAnimationFrame

    今天review同事代码,代码实现了返回顶部的功能,用到了lodash库中的throttle,我看着眼生,于是乎去看了下lodash文档,然后牵出了debounce,具体的知识点,这里不再赘述,底部的 ...

  8. python基础之反射、面向对象进阶

    isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象,如果是返回True 1 class F ...

  9. linux 操作之一 如何在linux将本地数据*.sql文件导入到linux 云服务器上的mysql数据库

    liunx 版本ubuntu 16.4 mysql 版本  5.6 1)准备*.sql文件 (* 是准备导入的sql文件的名字) 2)liunx 远程客户端  SecureCRT 7.0 alt+p ...

  10. luogu4172 [WC2006]水管局长

    就是用 lct 维护最小生成树 ref #include <algorithm> #include <iostream> #include <cstdio> #in ...