728x90
문제
Table: Employee
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
+--------------+---------+
id is the primary key (column with unique values) for this table.
departmentId is a foreign key (reference columns) of the ID from the Department table.
Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
Table: Department
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key (column with unique values) for this table. It is guaranteed that department name is not NULL.
Each row of this table indicates the ID of a department and its name.
Write a solution to find employees who have the highest salary in each of the departments.
Return the result table in any order.
The result format is in the following example.
풀이
SELECT
D.name AS 'Department',
E.name AS 'Employee',
Salary
FROM Employee E JOIN Department D
ON E.departmentId = D.id
WHERE
(E.DepartmentId, Salary) IN
(SELECT DepartmentId, MAX(Salary) FROM Employee Group by DepartmentId)
728x90
'문제풀이 > SQL' 카테고리의 다른 글
Python 개발자 찾기 (0) | 2024.04.06 |
---|---|
업그레이드 된 아이템 구하기 (0) | 2024.04.06 |
181. Employees Earning More Than Their Managers (0) | 2023.08.20 |
leetcode / Customers Who Never Order (0) | 2023.08.14 |
LeetCode / Reformat Department Table (0) | 2023.08.13 |
댓글