문제풀이/SQL
181. Employees Earning More Than Their Managers
monawa
2023. 8. 20. 18:59
728x90
https://leetcode.com/problems/employees-earning-more-than-their-managers/
Employees Earning More Than Their Managers - LeetCode
Can you solve this real interview question? Employees Earning More Than Their Managers - Table: Employee +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | | salary | int | | managerId | int | +------
leetcode.com
문제
Table: Employee
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
+-------------+---------+
id is the primary key (column with unique values) for this table.
Each row of this table indicates the ID of an employee, their name, salary, and the ID of their manager.
Write a solution to find the employees who earn more than their managers.
Return the result table in any order.
Example 1:
Input:
Employee table:
+----+-------+--------+-----------+
| id | name | salary | managerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | Null |
| 4 | Max | 90000 | Null |
+----+-------+--------+-----------+
Output:
+----------+
| Employee |
+----------+
| Joe |
+----------+
Explanation: Joe is the only employee who earns more than his manager.
풀이
SELECT E.Name AS Employee
FROM Employee E JOIN Employee M
on E.ManagerId = M.Id
WHERE E.Salary > M.Salary
관리자보다 더많은 급여를 받는 직원을 찾기위해 테이블을 직원 , 매니저로 지칭하여 2개룰 합쳐준후
ID와 매니저 ID가 같은 컬럼중 직원의 소득이 높은 사람을 선택합니다
728x90