Skip to content

Commit 22dc110

Browse files
committed
finish 181, 182
1 parent e5bee8a commit 22dc110

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# 181. Employees Earning More Than Their Managers
2+
3+
- Difficulty: Easy.
4+
- Related Topics: .
5+
- Similar Questions: .
6+
7+
## Problem
8+
9+
The ```Employee``` table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
10+
11+
```
12+
+----+-------+--------+-----------+
13+
| Id | Name | Salary | ManagerId |
14+
+----+-------+--------+-----------+
15+
| 1 | Joe | 70000 | 3 |
16+
| 2 | Henry | 80000 | 4 |
17+
| 3 | Sam | 60000 | NULL |
18+
| 4 | Max | 90000 | NULL |
19+
+----+-------+--------+-----------+
20+
```
21+
22+
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.
23+
24+
```
25+
+----------+
26+
| Employee |
27+
+----------+
28+
| Joe |
29+
+----------+
30+
```
31+
32+
## Solution 1
33+
34+
```sql
35+
# Write your MySQL query statement below
36+
select
37+
a.Name as Employee
38+
from Employee a
39+
left join Employee b
40+
on a.ManagerId = b.Id
41+
where a.Salary > b.Salary
42+
```
43+
44+
**Explain:**
45+
46+
nope.
47+
48+
**Complexity:**
49+
50+
* Time complexity :
51+
* Space complexity :
52+
53+
## Solution 2
54+
55+
```sql
56+
# Write your MySQL query statement below
57+
select
58+
a.Name as Employee
59+
from Employee a, Employee b
60+
where a.ManagerId = b.Id
61+
and a.Salary > b.Salary
62+
```
63+
64+
**Explain:**
65+
66+
nope.
67+
68+
**Complexity:**
69+
70+
* Time complexity :
71+
* Space complexity :

101-200/182. Duplicate Emails.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 182. Duplicate Emails
2+
3+
- Difficulty: Easy.
4+
- Related Topics: .
5+
- Similar Questions: .
6+
7+
## Problem
8+
9+
Write a SQL query to find all duplicate emails in a table named ```Person```.
10+
11+
```
12+
+----+---------+
13+
| Id | Email |
14+
+----+---------+
15+
16+
17+
18+
+----+---------+
19+
```
20+
21+
For example, your query should return the following for the above table:
22+
23+
```
24+
+---------+
25+
| Email |
26+
+---------+
27+
28+
+---------+
29+
```
30+
31+
**Note**: All emails are in lowercase.
32+
33+
## Solution 1
34+
35+
```sql
36+
# Write your MySQL query statement below
37+
select Email
38+
from Person
39+
group by Email
40+
having count(Id) > 1
41+
```
42+
43+
**Explain:**
44+
45+
nope.
46+
47+
**Complexity:**
48+
49+
* Time complexity :
50+
* Space complexity :
51+
52+
## Solution 2
53+
54+
```sql
55+
# Write your MySQL query statement below
56+
select
57+
distinct a.Email as Email
58+
from Person a, Person b
59+
where a.Id <> b.Id
60+
and a.Email = b.Email
61+
```
62+
63+
**Explain:**
64+
65+
nope.
66+
67+
**Complexity:**
68+
69+
* Time complexity :
70+
* Space complexity :

0 commit comments

Comments
 (0)