혜온의 이것저것

[HackerRank] Weather Observation Station 20 (MySQL) 본문

Data Analysis/SQL

[HackerRank] Weather Observation Station 20 (MySQL)

혜온 :) 2022. 8. 22. 10:25

https://www.hackerrank.com/challenges/weather-observation-station-20/problem?isFullScreen=true 

 

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.

 

풀이
set @r=0;
select round(avg(lat_n),4)
from (select (@r:=@r+1) as r, lat_n from station order by lat_n) s
where 
    r=(select ceil(count(*)/2)from station) or
    r=(select floor(count(*)/2+1) from station)
Comments