Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c7986f

Browse files
committedFeb 18, 2017
update: 1 solution
1 parent 5987598 commit 0c7986f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Progress: 9/
1313
|177|[Nth Highest Salary](https://leetcode.com/problems/nth-highest-salary/)| [SQL](./src/nth-highest-salary/res.txt)|Medium|
1414
|181|[Employees Earning More Than Their Managers](https://leetcode.com/problems/employees-earning-more-than-their-managers/) | [SQL](./src/employees-earning-more-than-their-managers/res.txt)|Easy|
1515
|182|[Duplicate Emails](https://leetcode.com/problems/duplicate-emails/) | [SQL](./src/duplicate-emails/res.txt)|Easy|
16+
|184|[Department Highest Salary](https://leetcode.com/problems/department-highest-salary/) | [SQL](./src/department-highest-salary/res.txt)|Medium|
1617
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/) | [SQL](./src/rising-temperature/res.txt)|Easy|
1718
|434|[Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string/) | [JavaScript](./src/number-of-segments-in-a-string/res.js)|Easy|

‎src/department-highest-salary/res.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.
2+
3+
-- +----+-------+--------+--------------+
4+
-- | Id | Name | Salary | DepartmentId |
5+
-- +----+-------+--------+--------------+
6+
-- | 1 | Joe | 70000 | 1 |
7+
-- | 2 | Henry | 80000 | 2 |
8+
-- | 3 | Sam | 60000 | 2 |
9+
-- | 4 | Max | 90000 | 1 |
10+
-- +----+-------+--------+--------------+
11+
-- The Department table holds all departments of the company.
12+
13+
-- +----+----------+
14+
-- | Id | Name |
15+
-- +----+----------+
16+
-- | 1 | IT |
17+
-- | 2 | Sales |
18+
-- +----+----------+
19+
-- Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, Max has the highest salary in the IT department and Henry has the highest salary in the Sales department.
20+
21+
-- +------------+----------+--------+
22+
-- | Department | Employee | Salary |
23+
-- +------------+----------+--------+
24+
-- | IT | Max | 90000 |
25+
-- | Sales | Henry | 80000 |
26+
-- +------------+----------+--------+
27+
28+
# Write your MySQL query statement below
29+
SELECT b.Name AS 'Department', a.Name AS 'Employee', a.Salary AS 'Salary' FROM Employee a
30+
inner join (SELECT MAX(Salary) AS 'salary', DepartmentId as 'id' FROM Employee GROUP BY DepartmentId) c
31+
ON a.Salary = c.salary AND a.DepartmentId=c.id
32+
inner join Department b
33+
ON a.DepartmentId=b.Id

0 commit comments

Comments
 (0)
Please sign in to comment.