Employees Earning More Than Their Managers


  • 0
    D

    Below is the link to my sqlfiddle where my code works. i don't know why my code isn't accepted in here in OJ.
    http://sqlfiddle.com/#!9/81240/1
    If the link isn't accessible below is the meta-data to create the dummy data:

    CREATE TABLE Employee(
    Id int,
    Name Varchar(50),
    Salary int,
    ManagerId int
    );
    
    INSERT INTO Employee VALUES(1, "Mark", 30000, 2);
    INSERT INTO Employee VALUES(2, "Jack", 20000, NULL);
    
    SELECT 
    E.Name as Employee
    FROM 
    (SELECT Name, ManagerId, Salary
    FROM Employee 
    WHERE ManagerId IS NOT NULL) E
    INNER JOIN 
    (SELECT Id, Salary
    FROM Employee 
    WHERE ManagerId IS NULL)M
    ON E.ManagerId = M.Id
    AND E.Salary > M.Salary

  • 0
    _

    1. You don't need to create table
    2. You don't need to provide data
    3. It requests to output "Name" as "Employee"

  • 0
    D
    1. Read my comments properly. I gave that for someone to test my data against using sqlfiddle for which I even provided the link. Otherwise s/he cannot test my sql.
    2. And even adding Employee as alias doesn't work.

  • 0
    _

    Er...when I remove 'WHERE ManagerId IS NULL', it work..-_-!
    I guess, some 'Employee' have 'Manager', but 'Manager' also have 'Manager'


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.