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 med AS (Select * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY Lat_n) as rn, Lat_n, LEAD(lat_n,1) OVER (ORDER BY lat_n) as x
FROM Station
) AS temp
WHERE rn=(CEILING(@ec/2))
)
SELECT case
WHEN @ec%2=1 THEN ROUND(lat_n,4)
WHEN @ec%2=0 THEN ROUND((lat_n+x)/2,4) END
FROM med
;
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 →
SET @ec = (SELECT COUNT(lat_n) FROM station);
WITH med AS (Select * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY Lat_n) as rn, Lat_n, LEAD(lat_n,1) OVER (ORDER BY lat_n) as x FROM Station ) AS temp WHERE rn=(CEILING(@ec/2)) ) SELECT case WHEN @ec%2=1 THEN ROUND(lat_n,4) WHEN @ec%2=0 THEN ROUND((lat_n+x)/2,4) END FROM med
;