We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
with ordered as (
select lat_n, row_number() over (order by lat_n) as row_num from station
),
counts as (
select count(lat_n) as total from ordered
),
median_vals as (
select o.lat_n, c.total
from ordered o
cross join counts c
where o.row_num = floor((c.total + 1)/2)
or o.row_num = ceil((c.total + 1)/2)
)
select round(avg(lat_n), 4) as median from median_vals;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 20
You are viewing a single comment's thread. Return to all comments →
with ordered as ( select lat_n, row_number() over (order by lat_n) as row_num from station ), counts as ( select count(lat_n) as total from ordered ), median_vals as ( select o.lat_n, c.total from ordered o cross join counts c where o.row_num = floor((c.total + 1)/2) or o.row_num = ceil((c.total + 1)/2) ) select round(avg(lat_n), 4) as median from median_vals;