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 e7e35ba

Browse files
authored
Update 571. Find Median Given Frequency of Numbers.sql
Changes
1 parent 510736c commit e7e35ba

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

‎hard/571. Find Median Given Frequency of Numbers.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ WITH cte AS(
77
),
88
cte2 AS(
99
SELECT number,frequency,
10-
CASE WHEN (LAG(e::INT,1,1) OVER w)=1 THEN (LAG(e::INT,1,1) OVER w) ELSE (LAG(e::INT,1,1) OVER w )+1 END AS s,e,t
10+
CASE WHEN (LAG(e::INT,1) OVER w) IS NULL THEN 1 ELSE (LAG(e::INT,1) OVER w)+1 END AS s,
11+
e,t
1112
FROM cte
1213
WINDOW w AS (ORDER BY number)
1314
)
1415

15-
SELECT ROUND(AVG(number),2)
16+
SELECT ROUND(AVG(number),1)
1617
FROM cte2
1718
WHERE (t::NUMERIC/2 BETWEEN s AND e) OR (t::NUMERIC/2+1 BETWEEN s AND e);
1819

0 commit comments

Comments
(0)

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