Skip to content
Onsite

Employees earning more than their managers

EasyP1Coding

Table employee:

ColumnType
idint (primary key)
nametext
salaryint
manager_idint (nullable, references employee.id)

Write a query that returns the names of employees who earn more than their direct manager. Return one column named employee.

Schema

CREATE TABLE employee (
  id int PRIMARY KEY,
  name text NOT NULL,
  salary int NOT NULL,
  manager_id int REFERENCES employee(id)
);

Example 1

Input
employee: (1, 'Joe', 70, 3), (2, 'Henry', 80, 4), (3, 'Sam', 60, NULL), (4, 'Max', 90, NULL)
Output
employee: Joe
Why
Joe earns 70, his manager Sam earns 60. Henry earns less than Max.

Constraints

  • PostgreSQL dialect.
  • manager_id is NULL for people without a manager; they are never in the result.
  • Return rows in any order.

Hints

PostgreSQL
Run checks the 2 visible tests, Submit all 6.