본문 바로가기
MYSQL/HakerRank_Medium

Weather Observation Station 19, 유클리드 거리 구하기

by 수스리 2025. 4. 16.

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 4 decimal digits.

 

2D 평면상 P1(a, b)와 P2(b, d)들을 고려하세요. (a, b)는 북위 최소값과 최대값이고 (c, d)는 서경 최소 값과 최대값이 입니다. 각각 점들로 유클리드 거리를 구하고  소수점 4자리 까지 반올림하세요

 

 

SELECT ROUND(SQRT(POW((MAX(LAT_N) - MIN(LAT_N)), 2) + POW((MAX(LONG_W) - MIN(LONG_W)), 2)), 4)
FROM STATION

우선 유클리드 거리 구하는 방법부터 알아야 합니다. 저는 몰랐어요.

√[(x₂ - x₁)² + (y₂ - y₁)²]

공식을 그대로 쓰면 됩니다. 이 문제는 숫자 함수를 잘 아냐 묻는 함수 같네요. 제곱과 제곱근은 평소에 써본적이 없는데 오늘 처음 써보네요

제곱 함수 : 

POW(숫자, 얼마나 제곱할지)

게곱근 :

SQRT(숫자)

'MYSQL > HakerRank_Medium' 카테고리의 다른 글

The Report : JOIN을 이렇게도 쓸 수 있구나!  (0) 2025.04.17
Weather Observation Station 20(중앙값 구하기)  (0) 2025.04.16
Weather Observation Station 18  (0) 2025.04.15
New Companies  (0) 2025.04.15
Binary Tree Nodes  (0) 2025.04.14