[HackerRank] Weather Observation Station 18

당당·2023년 7월 16일
0

HackerRank

목록 보기
10/27

https://www.hackerrank.com/challenges/weather-observation-station-18/problem

📔문제

Consider P1(a,b) and P2(c,d) to be two points on a 2D plane.

  • a happens to equal the minimum value in Northern Latitude (LAT_N in STATION).
  • b happens to equal the minimum value in Western Longitude (LONG_W in STATION).
  • c happens to equal the maximum value in Northern Latitude (LAT_N in STATION).
  • d happens to equal the maximum value in Western Longitude (LONG_W in STATION).

Query the Manhattan Distance between points P1 and P2 and round it to a scale of 4 decimal places.

The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.


🧮분야

  • AGGREGATION

📃SQL 코드

select round(abs(c-a)+abs(d-b),4)
from (select min(lat_n) a
     from station),
     (select min(long_w) b
     from station),
     (select max(lat_n) c
     from station),
     (select max(long_w) d
     from station);

📰출력 결과


📂고찰

맨해튼 거리|c-a|+|d-b|로 구할 수 있다.

profile
MySQL DBA 신입

0개의 댓글