[HackerRank MySQL] Weather Observation Station 20

2021. 2. 25. 13:37Today I Learned.../MySQL

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

select round(lat_n, 4)
from station s
where (select count(*) from station where lat_n>s.lat_n)
    = (select count(*) from station where lat_n<s.lat_n)

Reference: HackerRank Practice > SQL > Aggregation > Weather Observation Station 20