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.
total Number of them is 8....the median=(Number(n/2)+Number(n/2)+1)/2
say the data set count=500 instead of 499
Number(n/2)=250
Number(n/2)+1=251
then you get the average:
WITH CTE AS (SELECT TOP(2)
CASE
WHEN ROW_NUMBER() OVER(ORDER BY LAT_N )=250 OR ROW_NUMBER() OVER(ORDER BY LAT_N )=251
THEN ROUND(CONVERT(DECIMAL(10, 4), LAT_N), 4)
END AS M
FROM STATION
ORDER BY M DESC)
SELECT ROUND(CONVERT(DECIMAL(10, 4), AVG(M)), 4)
FROM CTE
WHERE M IS NOT NULL
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 5
You are viewing a single comment's thread. Return to all comments →
To calc the median For even number..
EX: 2 4 5 (6 7) 8 10 12 order ASC 1 2 3 4 5 6 7 8
total Number of them is 8....the median=(Number(n/2)+Number(n/2)+1)/2
say the data set count=500 instead of 499
Number(n/2)=250 Number(n/2)+1=251
then you get the average:
WITH CTE AS (SELECT TOP(2) CASE WHEN ROW_NUMBER() OVER(ORDER BY LAT_N )=250 OR ROW_NUMBER() OVER(ORDER BY LAT_N )=251 THEN ROUND(CONVERT(DECIMAL(10, 4), LAT_N), 4) END AS M FROM STATION ORDER BY M DESC)
SELECT ROUND(CONVERT(DECIMAL(10, 4), AVG(M)), 4) FROM CTE WHERE M IS NOT NULL