You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|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|
|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|
-- 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
0 commit comments