1270. All People Report to the Given Manager

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| employee_id   | int     |
| employee_name | varchar |
| manager_id    | int     |
+---------------+---------+
employee_id is the primary key for this table.
Each row of this table indicates that the employee with ID employee_id and name employee_name reports his work to his/her direct manager with manager_id
The head of the company is the employee with employee_id = 1.

 

Write an SQL query to find employee_id of all employees that directly or indirectly report their work to the head of the company.

The indirect relation between managers will not exceed 3 managers as the company is small.

Return result table in any order without duplicates.

The query result format is in the following example:

Employees table:
+-------------+---------------+------------+
| employee_id | employee_name | manager_id |
+-------------+---------------+------------+
| 1           | Boss          | 1          |
| 3           | Alice         | 3          |
| 2           | Bob           | 1          |
| 4           | Daniel        | 2          |
| 7           | Luis          | 4          |
| 8           | Jhon          | 3          |
| 9           | Angela        | 8          |
| 77          | Robert        | 1          |
+-------------+---------------+------------+

Result table:
+-------------+
| employee_id |
+-------------+
| 2           |
| 77          |
| 4           |
| 7           |
+-------------+

The head of the company is the employee with employee_id 1.
The employees with employee_id 2 and 77 report their work directly to the head of the company.
The employee with employee_id 4 report his work indirectly to the head of the company 4 --> 2 --> 1. 
The employee with employee_id 7 report his work indirectly to the head of the company 7 --> 4 --> 2 --> 1.
The employees with employee_id 3, 8 and 9 don't report their work to head of company directly or indirectly. 
SELECT e3.employee_id
FROM employees e1 LEFT JOIN employees e2
ON e1.employee_id = e2.manager_id
LEFT JOIN employees e3
ON e2.employee_id = e3.manager_id
WHERE e1.manager_id = 1 AND e3.employee_id !=1;
SELECT e1.employee_id
FROM Employees e1 
JOIN Employees e2 ON e1.manager_id = e2.employee_id
JOIN Employees e3 ON e2.manager_id = e3.employee_id
WHERE e1.employee_id <> 1 AND e3.manager_id = 1;

 

Sloppy People vs. Neat People Sloppy people and neat people are two different types of individuals with distinct personality traits. Sloppy people tend to be more relaxed and carefree, while neat people are often more organized and detail-oriented. Both types of people have their own unique strengths and weaknesses. Sloppy people are often creative and spontaneous. They tend to prioritize fun and enjoyment over order and structure. They are comfortable with chaos and can adapt easily to changing situations. They are also great at improvising and finding new solutions to problems. However, their lack of organization can sometimes lead to disarray and confusion. They may struggle to meet deadlines or remember important tasks. On the other hand, neat people prefer structure and order. They like to have a plan and stick to it. They are detail-oriented and take pride in their work. They are often reliable and responsible. They are also great at managing their time and resources efficiently. However, their attention to detail can sometimes lead to perfectionism and rigidity. They may struggle to be flexible or adapt when things don't go according to plan. In terms of living spaces, sloppy people tend to have cluttered and messy environments. They may have clothes strewn about or dishes piled up in the sink. Neat people, on the other hand, prefer clean and organized spaces. They may have a place for everything and everything in its place. They like to keep their living spaces tidy and free of clutter. In conclusion, both sloppy people and neat people have their own unique strengths and weaknesses. Sloppy people tend to be creative and adaptable, while neat people are organized and responsible. It's important to recognize and appreciate these differences, as they can add diversity and balance to our lives. Whether you're a sloppy person or a neat person, it's important to embrace your strengths and work on improving your weaknesses. By doing so, you can create a more fulfilling and productive life.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值