Algorithm
Problem Name: Sql -
In this HackerRank Functions in SQL problem solution,
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 Northern Latitude (LAT_N in STATION).
Query the Manhattan Distance between points P1 and P2and round it to a scale of 4 decimal places.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Code Examples
#1 Code Example with MySQL
Code -
MySQL
select round(abs(min(lat_n)-max(lat_n))+abs(min(long_w)-max(long_w)),4) from station;
Copy The Code &
Try With Live Editor