https://www.hackerrank.com/challenges/weather-observation-station-18/problem?isFullScreen=true
Weather Observation Station 18 | HackerRank
Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.
www.hackerrank.com

Solution #MySQL
select round((abs(A.a-A.c)+abs(A.b-A.d)),4) as manhattn
from(select min(LAT_N) a, min(LONG_W) b, max(LAT_N) c, max(LONG_W) d
from STATION
)A
Manhattan Distance : |a-c|+|b-d|
절댓값 함수 abs , 반올림 함수 round
서브쿼리 부분 Alias 설정이 필요하다는 에러만 해결하면 문제 풀이 완료
조금 더 쿼리를 축소시켜보았다.
select round((abs(min(LAT_N)-max(LAT_N))+abs(min(LONG_W)-max(LONG_W))),4)
from STATION
'Database > SQL' 카테고리의 다른 글
[presto] insert partition table (0) | 2023.01.12 |
---|---|
hackerrank / Weather Observation Station 19 (0) | 2022.05.23 |
Hackerrank / Symmetric Pairs (0) | 2022.04.29 |
Hackerrank / Placements (0) | 2022.03.08 |
Hackerrank / Ollivander's Inventory (0) | 2022.01.22 |