Leetcode 175번 Combine Two Tables 문제 풀이
분류: SELECT, JOIN
https://leetcode.com/problems/employees-earning-more-than-their-managers/
SELECT e.name AS 'Employee'
FROM Employee as e
WHERE salary > (SELECT Salary FROM Employee AS m WHERE m.id = e.managerId);
employee 테이블에서 각 id 마다 매니저 id로 월급을 찾아서 비교한다.
SELECT e.name AS 'Employee'
FROM Employee AS e, Employee AS m
WHERE e.managerId = m.id AND e.salary > m.salary;
이전 풀이보다 좀 더 깔끔한 풀이이다.
SELECT e.name AS 'Employee'
FROM Employee AS e JOIN Employee AS m
ON e.managerId = m.id AND e.salary > m.salary;
JOIN을 이용하여 Employee와 Manager 테이블을 만들어 조건에 맞게 합쳤다.