Skip to content

Commit 7ec54e1

Browse files
authored
Create 0181-employees-earning-more-than-their-managers.sql
1 parent 9297ff6 commit 7ec54e1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- LeetCode Problem: 181. Employees Earning More Than Their Managers
2+
-- https://leetcode.com/problems/employees-earning-more-than-their-managers/
3+
--
4+
-- Description:
5+
-- The Employee table holds all employees including their managers.
6+
-- Every employee has an Id, and there is also a column for the manager Id.
7+
-- Return the list of employees who earn more than their managers.
8+
--
9+
-- Employee table schema:
10+
-- +----+-------+--------+-----------+
11+
-- | Id | Name | Salary | ManagerId |
12+
-- +----+-------+--------+-----------+
13+
--
14+
-- Example:
15+
-- Input:
16+
-- Employee table:
17+
-- +----+-------+--------+-----------+
18+
-- | Id | Name | Salary | ManagerId |
19+
-- +----+-------+--------+-----------+
20+
-- | 1 | Joe | 70000 | 3 |
21+
-- | 2 | Henry | 80000 | 4 |
22+
-- | 3 | Sam | 60000 | NULL |
23+
-- | 4 | Max | 90000 | NULL |
24+
-- Output:
25+
-- +----------+
26+
-- | Employee |
27+
-- +----------+
28+
-- | Joe |
29+
-- +----------+
30+
31+
-- Solution:
32+
SELECT e.name AS Employee
33+
FROM Employee e
34+
JOIN Employee m ON e.managerId = m.id
35+
WHERE e.salary > m.salary;

0 commit comments

Comments
 (0)