https://leetcode.com/problems/department-highest-salary/
Problem
Analysis
1. Employee의 DepartmentId 와 Department의 Id가 같은 곳을 JOIN한다.
2. 그중에 MAX함수를 사용하여 Salary가 높은 곳을 찾는다.
Solution
SELECT D.NAME AS Department,E.Name AS Employee, E.Salary
FROM Employee AS E
JOIN Department AS D ON E.DepartmentId = D.Id
AND E.Salary = (
SELECT MAX(Salary)
FROM Employee AS T
WHERE T.DepartmentId = E.DepartmentId
);
'Algorithm > SQL' 카테고리의 다른 글
[SQL][sqlzoo] SELECT from world (0) | 2020.07.02 |
---|---|
[SQL][sqlzoo] SELECT basics (0) | 2020.07.02 |
[SQL][Leetcode] 183. Customers Who Never Order (0) | 2020.06.21 |
[SQL][Leetcode] 182. Duplicate Emails (0) | 2020.06.21 |
[SQL][Leetcode] 181. Employees Earning More Than Their Managers (0) | 2020.06.21 |