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
     
  • 相关阅读:
    chrome被篡改 导航到搜狗 或者特殊页面
    安装tomcat jdk
    监控tomcat 启动
    关于如何关闭445端口
    python模拟大数据登陆
    搭建vsftpd服务
    kali syn洪水攻击实例
    HP880G3 安装RHEL6.5
    Python_列表
    Python第一个请求接口
  • 原文地址:https://www.cnblogs.com/little-YTMM/p/5244948.html
Copyright © 2011-2022 走看看