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. IDEA中使用插件添加更多可选择的主题,使代码高亮,缓解视觉疲劳

    1.点击 File-->settings(或Ctrl+Shift+S)打开IDE设置面板 点击plugins-->右侧选择Marketplace-->搜索框中输入Material-- ...

  2. JAVAOOP多线程

    进程每个独立运行的任务对应一个进程,每个进程可以产生多个线程 特点:1,进程是系统运行程序的基本单位 2,每一个进程都有自己独立的一块内存空间,一组系统资源 3,每一个进程的内部数据和状态都是完全独立 ...

  3. Yaf学习(一)----Linux安装Yaf

    1.简介 Yaf,全称 Yet Another Framework,是一个高性能的PHP开发框架,采用PHP扩展实现(c语言).Blablablabla....... 2.环境 2.1 虚拟机 虚拟机 ...

  4. python爬虫之有道在线翻译

    今天初学了python这门课 老师简单的讲解了一下 python的安装环境,配置环境变量,当前主流Python使用的是3.x版本, 下午简单的讲解了python的起源,发展以及在各个方面的应用 然后晚 ...

  5. HDOJ 1176 免费馅饼(完全背包)

    参考:https://blog.csdn.net/hhu1506010220/article/details/52369785 https://blog.csdn.net/enjoying_scien ...

  6. poj 2393 奶牛场生产成本问题 贪心算法

    题意:有一个奶牛场,第i周的生产成本为c,需要数量为 y,每周的存储成本为s.问怎么安排使得成本最低? 思路: 成本最低是吧?求出每周的最低成本*该周需要的数量就是成本最低 每周的成本有两个:自己本周 ...

  7. 线程基础三 使用C#中的lock关键词

    C#中lock关键字主要是为确保当一个线程使用某些资源时,同时无法其他线程无法使用该资源.下面我们看看下面的小例子. static void Main(string[] args) { var c = ...

  8. CDSビュー新規作成

    CDSビューの追加文書いついては以下の内容も参照してください. ABAP keyword documentation SAP Community. Step 1: CDSビュー作成 Favorite ...

  9. POJ 1568 Find the Winning Move

    Find the Winning Move 链接 题意: 4*4的棋盘,给出一个初始局面,问先手有没有必胜策略? 有的话输出第一步下在哪里,如果有多个,按(0, 0), (0, 1), (0, 2), ...

  10. mysql ON DUPLICATE KEY UPDATE、REPLACE INTO

    INSERT INTO ON DUPLICATE KEY UPDATE 与 REPLACE INTO,两个命令可以处理重复键值问题,在实际上它之间有什么区别呢?前提条件是这个表必须有一个唯一索引或主键 ...