Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Hacker Rank] Weather Observation Station 20 : MySQL

์ธ” 2022. 8. 2. 18:39

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š” 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

 

 

'Growth ๐ŸŒณ > Practice ๐Ÿ’ป' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Hacker Rank] Weather Observation Station 16  (0) 2022.08.22
[Hacker Rank] Weather Observation Station 14  (0) 2022.08.22
[Hacker Rank] The Blunder  (0) 2022.08.20
[SQL] ์—ฐ์Šต๋ฌธ์ œ  (0) 2022.08.03
[ํ•ด์ปค๋žญํฌ] Weather Observation Station 5  (0) 2022.07.28