Leetcode - 181. Employees Earning More Than Their Managers (서브쿼리로 다시풀기)

르네·2023년 11월 13일
0

SQL

목록 보기
53/63

문제

  1. Employees Earning More Than Their Managers

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.

The result format is in the following example.

풀이

나의 풀이

SELECT e.name AS Employee
FROM employee e
    INNER JOIN employee m ON e.managerId = m.id
WHERE e.salary > m.salary

다른 사람 풀이(서브쿼리 활용)

SELECT name AS Employee
FROM employee e
WHERE salary > (SELECT salary FROM employee m WHERE e.managerId = m.id)

배운점

  • WHERE 서브쿼리로 매니저보다 더 많이 버는 직원을 찾을 수 있었다.
profile
데이터분석 공부로그

0개의 댓글