[Hacker Rank] Weather Observation Station 20 : MySQL
๐ข ๋ณธ ํฌ์คํ ์ ํ์ฉ๋๋ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐ ์๋ฃ ์ถ์ฒ๋ HackerRank ์์ ๋ฐํ๋๋ค.
https://www.hackerrank.com
โ ๋ฌธ์
https://www.hackerrank.com/challenges/weather-observation-station-20/problem
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 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.
โ ํ์ด
SELECT ROUND(LAT_N, 4)
FROM (SELECT LAT_N, PERCENT_RANK() OVER (ORDER BY LAT_N) AS PR
FROM STATION) T1
WHERE T1.PR = 0.5;
PERCENT_RANK()
: ํํฐ์ ๊ฐ๋ณด๋ค ์์ ํํฐ์ ๊ฐ์ ๋ฐฑ๋ถ์จ์ ๋ฐํํ๋ค.
๋ฌธ์ ์์๋ ์ค์๊ฐ์ ์ถ์ถํ๋ผ๊ณ ํ์ผ๋ฏ๋ก ์กฐ๊ฑด์ ์ PERCENT_RANK()= 0.5 .
https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_percent-rank
MySQL :: MySQL 8.0 Reference Manual :: 12.21.1 Window Function Descriptions
12.21.1 Window Function Descriptions This section describes nonaggregate window functions that, for each row from a query, perform a calculation using rows related to that row. Most aggregate functions also can be used as window functions; see Section 12
dev.mysql.com