안녕하세요, HELLO
오늘은 Leetcode 알고리즘 문제 '181. Employees Earning More Than Their Managers'에 대해서 살펴보고자 합니다.
알고리즘 문제, 코드, 해설 그리고 Leetcode에서 제공해준 solution 순서대로 정리하였습니다.
STEP 1. 'Employees Earning More Than Their Managers' 알고리즘 문제
STEP 2. 'Employees Earning More Than Their Managers' 코드(code)
STEP 3. 'Employees Earning More Than Their Managers' 해설
STEP 4. 'Employees Earning More Than Their Managers' solution
STEP 1. 'Employees Earning More Than Their Managers' 알고리즘 문제
Write an SQL query to find the employees who earn more than their managers.
Return the result table in any order.
담당 매니저보다 월급을 더 받는 직원을 찾는 SQL query를 작성하면 됩니다.
이때 반환된 결과는 순서에 상관없습니다.
The query result format is in the following example.
STEP 2. 'Employees Earning More Than Their Managers' 코드(code)
■ Runtime: 446 ms, faster than 57.02% of MySQL online submissions for Employees Earning More Than Their Manager.
■ Memory Usage: 0B, less than 100.00% of MySQL online submissions for Employees Earning More Than Their Managers.
# Write your MySQL query statement below
SELECT e1.name as "Employee"
FROM Employee as e1, Employee as e2
WHERE e1.managerId = e2.id
AND e1.salary > e2.salary
STEP 3. 'Employees Earning More Than Their Managers' 해설
employee 테이블에서 2개의 테이블을 선언해서, 이때 managerId와 id가 같은 경우에서 salary가 더 높은 경우만을 반환하는 방법으로 접근했습니다. 이에 다른 접근 방식을 살펴보니, join을 통해서 테이블을 합쳐서 만들었습니다.
STEP 4. 'Employees Earning More Than Their Managers' solution
추가적으로, Leetcode에서 제공해준 solution 코드를 살펴보겠습니다.
■ Runtime: 373 ms, faster than 79.00% of MySQL online submissions for Employees Earning More Than Their Managers.
■ Memory Usage: 0B, less than 100.00% of MySQL online submissions for Employees Earning More Than Their Managers.
# Write your MySQL query statement below
select e1.name Employee
from employee as e1
join employee as e2
on e1.managerId = e2.id
where e1.salary > e2.salary
■ 마무리
오늘은 Leetcode 알고리즘 문제 '181.Employees Earning More Than Their Managers'에 대해서 알아봤습니다.
좋아요와 댓글 부탁드리며,
오늘 하루도 즐거운 날 되시길 기도하겠습니다 :)
감사합니다.
'PROGRAMMING > LeetCode' 카테고리의 다른 글
[Leetcode] 183. Customers Who Never Order_해설, 풀이, 설명 (0) | 2023.01.06 |
---|---|
[Leetcode] 182. Duplicate Emails_해설, 풀이, 설명 (0) | 2022.09.12 |
[Leetcode] 180. Consecutive Numbers_해설, 풀이, 설명 (0) | 2022.09.03 |
[Leetcode] 178. Rank Scores_해설, 풀이, 설명 (0) | 2022.08.21 |
[Leetcode] 177. Nth Highest Salary_해설, 풀이, 설명 (3) | 2022.08.20 |
댓글