Employees Earning More Than Their Managers

  • 0

    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.
    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);
    E.Name as Employee
    (SELECT Name, ManagerId, Salary
    FROM Employee 
    WHERE ManagerId IS NOT NULL) E
    (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
    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.