zoukankan      html  css  js  c++  java
  • LeetCode——Employees Earning More Than Their Managers

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

    这种单表比较条件,一般都是表内进行join操作.
    参照此思路,解题如下所示:

    # Write your MySQL query statement below
    SELECT 
        a.Name AS Employee 
    FROM Employee a, Employee b
    WHERE
        a.ManagerId = b.Id
        AND a.Salary > b.Salary; 
    

    运行效率在可以接受的范围,此外语句也较为清晰便于维护.

  • 相关阅读:
    JVM参数配置
    域渗透命令
    相对路径绝对路径
    ESPCMS的CSRF添加管理员账号
    nmap脚本nse的使用
    Nmap简单的漏扫
    MS08-067
    lcx用法
    给自己的服务器传文件 转自别人
    突破大文件上传 和内网ip的端口转发
  • 原文地址:https://www.cnblogs.com/jason1990/p/11642248.html
Copyright © 2011-2022 走看看