√https://www.hackerrank.com/challenges/weather-observation-station-19/problem
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.
Input Format
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.
[풀이]
Euclidean distance 공식은

그러므로 P1, P2의 유클리디안 거리를 구하기 위해서는 √(b-a)^2 + (d-c)^2 로 구하면 된다.
a는 MIN(LAT_N)
b는 MAX(LAT_N)
c는 MIN(LONG_W)
d는 MAX(LONG_W) 로 구할 수 있고,
제곱은 POWER()를 이용, 제곱근은 SQRT()를 이용, 반올림은 ROUND()를 이용한다.
[코드]
SELECT ROUND(SQRT(POWER(MIN(LAT_N)-MAX(LAT_N),2)+POWER(MAX(LONG_W)-MIN(LONG_W),2)),4)
FROM STATION'SQL > HackerRank' 카테고리의 다른 글
| [HackerRank/SQL] Binary Tree Nodes (0) | 2021.11.07 |
|---|---|
| [HackerRank/SQL] The PADS (0) | 2021.11.06 |
| [HackerRank/SQL] Weather Observation Station 18 (0) | 2021.10.30 |
| [HackerRank/SQL] Revising the Select Query II (0) | 2021.10.30 |
| [HackerRank/SQL] Revising the Select Query I (0) | 2021.10.30 |