zoukankan      html  css  js  c++  java
  • DataBase -- Employees Earning More Than Their Managers My Submissions Question

    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
     
  • 相关阅读:
    自动化基础知识
    第一章Google软件测试介绍
    《将博客搬至CSDN》
    二叉树的先序遍历和中序遍历分析(递归)
    java 部分快捷功能
    toString
    自增自减运算符剖析
    二进制数的直接表示
    编程中的&&和||
    npm 镜像地址设置
  • 原文地址:https://www.cnblogs.com/little-YTMM/p/5244948.html
Copyright © 2011-2022 走看看