Skip to content

Commit 96c3161

Browse files
refactor 569
1 parent 575d88c commit 96c3161

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

Diff for: database/_569.sql

-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
--569. Median Employee Salary
2-
-- The Employee table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.
3-
--
4-
--+-----+------------+--------+
5-
--|Id | Company | Salary |
6-
--+-----+------------+--------+
7-
--|1 | A | 2341 |
8-
--|2 | A | 341 |
9-
--|3 | A | 15 |
10-
--|4 | A | 15314 |
11-
--|5 | A | 451 |
12-
--|6 | A | 513 |
13-
--|7 | B | 15 |
14-
--|8 | B | 13 |
15-
--|9 | B | 1154 |
16-
--|10 | B | 1345 |
17-
--|11 | B | 1221 |
18-
--|12 | B | 234 |
19-
--|13 | C | 2345 |
20-
--|14 | C | 2645 |
21-
--|15 | C | 2645 |
22-
--|16 | C | 2652 |
23-
--|17 | C | 65 |
24-
--+-----+------------+--------+
25-
--
26-
--Write a SQL query to find the median salary of each company. Bonus points if you can solve it without using any built-in SQL functions.
27-
--
28-
--+-----+------------+--------+
29-
--|Id | Company | Salary |
30-
--+-----+------------+--------+
31-
--|5 | A | 451 |
32-
--|6 | A | 513 |
33-
--|12 | B | 234 |
34-
--|9 | B | 1154 |
35-
--|14 | C | 2645 |
36-
--+-----+------------+--------+
37-
381
select Id, Company, Salary from
392
(
403
select e.Id, e.Salary, e.Company, if( @prev = e.Company , @Rank := @Rank + 1, @Rank := 1) as rank, @prev := e.Company

0 commit comments

Comments
 (0)