Skip to content

Commit c7efa2d

Browse files
committed
feat: add sql solution to lc problem: No.0185
No.0185.Department Top Three Salaries
1 parent 2ad5f69 commit c7efa2d

File tree

3 files changed

+75
-17
lines changed

3 files changed

+75
-17
lines changed

solution/0100-0199/0185.Department Top Three Salaries/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,30 @@ WHERE
122122
) < 3
123123
```
124124

125+
```sql
126+
# Write your MySQL query statement below
127+
with t as (
128+
select
129+
departmentId,
130+
name,
131+
salary,
132+
dense_rank() over(
133+
partition by departmentId
134+
order by
135+
salary desc
136+
) as rk
137+
from
138+
Employee
139+
)
140+
select
141+
d.name Department,
142+
t.name Employee,
143+
salary Salary
144+
from
145+
t
146+
join Department d on t.departmentId = d.id
147+
where
148+
rk < 4
149+
```
150+
125151
<!-- tabs:end -->

solution/0100-0199/0185.Department Top Three Salaries/README_EN.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,30 @@ WHERE
118118
) < 3
119119
```
120120

121+
```sql
122+
# Write your MySQL query statement below
123+
with t as (
124+
select
125+
departmentId,
126+
name,
127+
salary,
128+
dense_rank() over(
129+
partition by departmentId
130+
order by
131+
salary desc
132+
) as rk
133+
from
134+
Employee
135+
)
136+
select
137+
d.name Department,
138+
t.name Employee,
139+
salary Salary
140+
from
141+
t
142+
join Department d on t.departmentId = d.id
143+
where
144+
rk < 4
145+
```
146+
121147
<!-- tabs:end -->
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
SELECT
2-
Department.NAME AS Department,
3-
Employee.NAME AS Employee,
4-
Salary
5-
FROM
6-
Employee,
7-
Department
8-
WHERE
9-
Employee.DepartmentId = Department.Id
10-
AND (SELECT
11-
COUNT(DISTINCT e2.Salary)
12-
FROM
13-
Employee e2
14-
WHERE
15-
e2.Salary > Employee.Salary
16-
AND Employee.DepartmentId = e2.DepartmentId
17-
) < 3
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
departmentId,
5+
name,
6+
salary,
7+
dense_rank() over(
8+
partition by departmentId
9+
order by
10+
salary desc
11+
) as rk
12+
from
13+
Employee
14+
)
15+
select
16+
d.name Department,
17+
t.name Employee,
18+
salary Salary
19+
from
20+
t
21+
join Department d on t.departmentId = d.id
22+
where
23+
rk < 4

0 commit comments

Comments
 (0)