Skip to content

Commit 3b1d770

Browse files
Create 1978. Employees Whose Manager Left the Company.sql
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com>
1 parent 494a968 commit 3b1d770

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
1978. Employees Whose Manager Left the Company
2+
Solved
3+
Easy
4+
Topics
5+
Companies
6+
SQL Schema
7+
Pandas Schema
8+
Table: Employees
9+
10+
+-------------+----------+
11+
| Column Name | Type |
12+
+-------------+----------+
13+
| employee_id | int |
14+
| name | varchar |
15+
| manager_id | int |
16+
| salary | int |
17+
+-------------+----------+
18+
In SQL, employee_id is the primary key for this table.
19+
This table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null).
20+
21+
22+
Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees table, but the reports still have their manager_id set to the manager that left.
23+
24+
Return the result table ordered by employee_id.
25+
26+
The result format is in the following example.
27+
28+
29+
30+
Example 1:
31+
32+
Input:
33+
Employees table:
34+
+-------------+-----------+------------+--------+
35+
| employee_id | name | manager_id | salary |
36+
+-------------+-----------+------------+--------+
37+
| 3 | Mila | 9 | 60301 |
38+
| 12 | Antonella | null | 31000 |
39+
| 13 | Emery | null | 67084 |
40+
| 1 | Kalel | 11 | 21241 |
41+
| 9 | Mikaela | null | 50937 |
42+
| 11 | Joziah | 6 | 28485 |
43+
+-------------+-----------+------------+--------+
44+
Output:
45+
+-------------+
46+
| employee_id |
47+
+-------------+
48+
| 11 |
49+
+-------------+
50+
51+
Explanation:
52+
The employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).
53+
Kalel's manager is employee 11, who is still in the company (Joziah).
54+
Joziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.
55+
56+
57+
58+
# Write your MySQL query statement below
59+
SELECT e1.employee_id
60+
FROM
61+
Employees AS e1
62+
LEFT JOIN Employees AS e2 ON e1.manager_id = e2.employee_id
63+
WHERE e1.salary < 30000 AND e1.manager_id IS NOT NULL AND e2.employee_id IS NULL
64+
ORDER BY 1;
65+

0 commit comments

Comments
 (0)