Skip to content

Commit 2d9197a

Browse files
authored
Create 569-median-employee-salary.sql
1 parent 1f58d41 commit 2d9197a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

569-median-employee-salary.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write your MySQL query statement below
2+
SELECT a.Id, a.Company, a.Salary
3+
FROM (
4+
SELECT e.Id, e.Company, e.Salary,
5+
IF(@prev = e.Company, @rank := @rank+1, @rank := 1) AS Ranking,
6+
@prev := e.Company
7+
FROM Employee e, (SELECT @rank := 0, @prev := 0) AS t
8+
ORDER BY e.Company, e.Salary #, e.Id
9+
) AS a, (
10+
SELECT Company, COUNT(*) AS cnt
11+
FROM Employee
12+
GROUP BY Company
13+
) AS b
14+
WHERE a.Company = b.Company AND Ranking IN (FLOOR((cnt+1)/2), FLOOR((cnt+2)/2));

0 commit comments

Comments
 (0)