HackerRank-Weather Observation Station 20
A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to 4 decimal places.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Solution
SET @row_number = 0;
SELECT ROUND(RN.LAT_N, 4)
FROM (SELECT LAT_N, (@row_number:=@row_number + 1) AS row_num
FROM STATION
ORDER BY LAT_N) AS RN
WHERE RN.row_num = (
SELECT
CASE WHEN MOD(COUNT(LAT_N), 2) = 0 THEN COUNT(LAT_N)/2
ELSE ROUND((COUNT(LAT_N) / 2 + (COUNT(LAT_N) + 1)/2)/2,0)
END AS EorO
FROM STATION)
Thank you for reading. I really appreciate your support . Your encouragement means a lot to me and helps me to keep writing. Thank you again for being a valued reader.