https://leetcode.com/problems/employees-earning-more-than-their-managers/
자신의 매니저보다 많이 버는 사람 구하는 문제
나의 풀이
SELECT
E.name AS Employee
FROM Employee E JOIN Employee M
ON E.managerId = M.id
WHERE E.salary > M.salary
;
매니저 id를 활용해서 Join 한 후 WHERE 구문으로 처리
비슷한 풀이
SELECT
a.NAME AS Employee
FROM Employee AS a JOIN Employee AS b
ON a.ManagerId = b.Id
AND a.Salary > b.Salary
;
Join 할때부터 AND로 처리하는 게 더 깔끔해 보인다.
SELECT
a.Name AS 'Employee'
FROM
Employee AS a,
Employee AS b
WHERE
a.ManagerId = b.Id
AND a.Salary > b.Salary
;
이렇게 FROM 에서 활용하는 방법도 있다
'Programming > LeetCode' 카테고리의 다른 글
[LeetCode] Customers Who Never Order (0) | 2022.03.31 |
---|---|
[LeetCode] Duplicate Emails (0) | 2022.03.31 |
[LeetCode] Consecutive Numbers (MySQL) (0) | 2022.03.31 |
[LeetCode] Combine Two Tables (MySQL) (0) | 2022.03.31 |
[LeetCode] Search a 2D Matrix (0) | 2022.03.30 |
댓글