Prepare > SQL > Aggregation > Weather Observation Station 18
2023. 5. 20. 21:13ㆍHackerRank-My SQL
Weather Observation Station 18 | HackerRank
Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.
www.hackerrank.com
문제
Consider P(a,b) and P(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 and and round it to a scale of 4 decimal places.
- 맨해튼 거리: 택시거리, |p1−q1|+|p2−q2|
코드
SELECT ROUND(ABS(MIN(LONG_W) - MAX(LONG_W)) + ABS(MIN(LAT_N) - MAX(LAT_N)),4) FROM STATION;
- ABS(~~) 절댓값을 취해줌
두 번째 시도
SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)), 4)
FROM STATION;
- 똑같네요
'HackerRank-My SQL' 카테고리의 다른 글
Prepare > SQL > Advanced Select > Binary Tree Nodes (0) | 2023.05.23 |
---|---|
Prepare > SQL > Aggregation > Weather Observation Station 19 (0) | 2023.05.22 |
Prepare > SQL > Aggregation > Weather Observation Station 17 (0) | 2023.05.18 |
Prepare > SQL > Aggregation > Weather Observation Station 16 (0) | 2023.05.18 |
Prepare > SQL > Aggregation > Weather Observation Station 15 (0) | 2023.05.18 |