관리 메뉴

오늘도 배운다

Weather Observation Station 19 / HackerRank, SQL, MySQL 본문

코딩테스트연습(SQL)

Weather Observation Station 19 / HackerRank, SQL, MySQL

LearnerToRunner 2022. 12. 26. 01:13

문제

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  and  and format your answer to display  decimal digits.

 

제출답안(MySQL)

-- Euclidean Distance between (a, c) and (b, d) = {(b-a)**2 + (d-c)**2}**0.5
SET @dist_ab := (SELECT MAX(lat_n)-MIN(lat_n) FROM station);
SET @dist_cd := (SELECT MAX(long_w)-MIN(long_w) FROM station);

SELECT ROUND(SQRT(POWER(@dist_ab,2)+POWER(@dist_cd,2)),4)

 

 

문제 바로가기(MySQL) 

 

728x90
Comments