[HackerRank MySQL] Weather Observation Station 18
2021. 2. 10. 14:25ㆍToday I Learned.../MySQL
Weather Observation Station 18
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.
Manhattan Distance
The distance between two points measured along axes at right angles.
In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Solution
select round(max(lat_n)-min(lat_n) + max(long_w)-min(long_w), 4)
from station
Reference: HackerRank Practice > SQL > Aggregation > Weather Observation Station 18
'Today I Learned... > MySQL' 카테고리의 다른 글
[HackerRank MySQL] Top Competitors (0) | 2021.02.15 |
---|---|
[HackerRank MySQL] New Companies (0) | 2021.02.10 |
[LeetCode MySQL] 175. Combine Two Tables (0) | 2021.02.10 |
[LeetCode MySQL] 182. Duplicate Emails (0) | 2021.02.10 |
[LeetCode MySQL] 595. Big Countries (0) | 2021.02.10 |