Algorithm/SQL
[SQL][HackerRank] Weather Observation Station 20
융무
2020. 6. 10. 18:37
Weather Observation Station 20 | HackerRank
Query the median of Northern Latitudes in STATION and round to 4 decimal places.
www.hackerrank.com
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.
Oracle
SELECT ROUND(MEDIAN(LAT_N),4) FROM STATION;
MySQL
SELECT ROUND(LAT_N,4)
FROM STATION AS S
WHERE (SELECT COUNT(*) FROM STATION WHERE LAT_N<S.LAT_N) =(SELECT COUNT(*) FROM STATION WHERE LAT_N>S.LAT_N);