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가 같은 컬럼중 직원의 소득이 높은 사람을 선택합니다
'문제풀이 > SQL' 카테고리의 다른 글
업그레이드 된 아이템 구하기 (0) | 2024.04.06 |
---|---|
184. Department Highest Salary (0) | 2023.08.20 |
leetcode / Customers Who Never Order (0) | 2023.08.14 |
LeetCode / Reformat Department Table (0) | 2023.08.13 |
String, Date 조건에 부합하는 중고거래 상태 조회하기 (0) | 2023.03.18 |
댓글