IT/코테문제

[Hacker Rank_MySQL]문제 풀이#Weather Observation Station 19

호랑구야 2022. 3. 1. 09:02

SQL > Aggregation > Weather Observation Station 19

 

Weather Observation Station 19 | HackerRank

Query the Euclidean Distance between two points and round to 4 decimal digits.

www.hackerrank.com

 

 

Consider P1(a, c) and P2(b, d) to be two points on a 2D plane where (a,b) are the respective minimum and maximum values of Northern Latitude (LAT_N) and (c, d) are the respective minimum and maximum values of Western Longitude (LONG_W) in STATION.

Query the Euclidean Distance between points P1 and P2 and format your answer to display  decimal digits.

 

빨간 글씨는 내가 문제를 풀 때 중요하다고 생각한 부분이다.

 

처음에 P1과 P2를 잘못보고 (a,b)와 (c,d)의 거리를 계속 구하려고 하다가 디스커션을 참고하고 나서야, 무엇을 잘 못 봤는지 확인했다. 어떤 문제던지 기초는 문제의 정확한 파악!

 

SELECT ROUND(SQRT(POWER((MAX(LAT_N) - MIN(LAT_N)), 2)
                  + POWER((MAX(LONG_W) - MIN(LONG_W)), 2)), 4)
FROM STATION
반응형