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
     
  • 相关阅读:
    数字三角形
    嵌套矩阵问题
    NKOJ1236 a^b
    历届试题 最大子阵
    【动态规划】最大连续子序列和,最大子矩阵和,最大m子段和
    历届试题 翻硬币
    历届试题 带分数
    用户模板和用户场景
    学习进度——第九周
    最大子数组——回调
  • 原文地址:https://www.cnblogs.com/little-YTMM/p/5244948.html
Copyright © 2011-2022 走看看