-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path181.employees-earning-more-than-their-managers.sql
51 lines (48 loc) · 1.44 KB
/
181.employees-earning-more-than-their-managers.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--
-- @lc app=leetcode id=181 lang=mysql
--
-- [181] Employees Earning More Than Their Managers
--
-- https://leetcode.com/problems/employees-earning-more-than-their-managers/description/
--
-- database
-- Easy (55.86%)
-- Likes: 582
-- Dislikes: 76
-- Total Accepted: 182.6K
-- Total Submissions: 320.8K
-- Testcase Example: '{"headers": {"Employee": ["Id", "Name", "Salary", "ManagerId"]}, "rows": {"Employee": [[1, "Joe", 70000, 3], [2, "Henry", 80000, 4], [3, "Sam", 60000, null], [4, "Max", 90000, null]]}}'
--
-- The Employee table holds all employees including their managers. Every
-- employee has an Id, and there is also a column for the manager Id.
--
--
-- +----+-------+--------+-----------+
-- | Id | Name | Salary | ManagerId |
-- +----+-------+--------+-----------+
-- | 1 | Joe | 70000 | 3 |
-- | 2 | Henry | 80000 | 4 |
-- | 3 | Sam | 60000 | NULL |
-- | 4 | Max | 90000 | NULL |
-- +----+-------+--------+-----------+
--
--
-- Given the Employee table, write a SQL query that finds out employees who
-- earn more than their managers. For the above table, Joe is the only employee
-- who earns more than his manager.
--
--
-- +----------+
-- | Employee |
-- +----------+
-- | Joe |
-- +----------+
--
--
--
-- @lc code=start
-- Write your MySQL query statement below
SELECT a.Name as Employee
FROM Employee a INNER JOIN Employee b ON a.ManagerId = b.Id
WHERE a.Salary > b.Salary
-- @lc code=end