Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69df39b

Browse files
authored
Update 569. Median Employee Salary.sql
Updated Solution
1 parent e7e35ba commit 69df39b

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

‎hard/569. Median Employee Salary.sql

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
WITH sorted AS(
2-
SELECT *,
3-
ROW_NUMBER() OVER w1 AS row_num,
4-
COUNT(*) OVER w2 AS count
1+
WITH cte AS (
2+
SELECT id,company,salary,
3+
ABS(ROW_NUMBER() OVER (PARTITION BY company ORDER BY salary,id) - ROW_NUMBER() OVER (PARTITION BY company ORDER BY salary DESC,id DESC)) AS diff
54
FROM employee_569
6-
WINDOW w1 AS (PARTITION BY company ORDER BY salary),
7-
w2 AS (PARTITION BY company)
85
)
9-
10-
SELECT company,ROUND(AVG(salary),2)
11-
FROM sorted
12-
WHERE row_num BETWEEN count::NUMERIC/2 AND count::NUMERIC/2 + 1
13-
GROUP BY company;
6+
SELECT id,company,salary
7+
FROM cte
8+
WHERE diff = 0 OR diff = 1;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /