Algorithm
Problem Name: Sql -
In this HackerRank Functions in SQL problem solution,
Consider P1(a,c) and P2(b,d) to be two points on a 2D plane where (a,b) are the respective minimum and maximum values of Northern Latitude (LAT_N) and (c,d) are the respective minimum and maximum values of Western Longitude (LONG_W) in STATION.
Query the Euclidean Distance between points P1 and P2 and format your answer to display 4 decimal digits.
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
SET @a = (SELECT MIN(lat_n) FROM station);
SET @b = (SELECT MAX(lat_n) FROM station);
SET @c = (SELECT MIN(long_w) FROM station);
SET @d = (SELECT MAX(long_w) FROM station);
SET @distance = SQRT(POW(ABS(@a - @b), 2) + POW(ABS(@c - @d), 2));
SELECT FORMAT(@distance, 4);
Copy The Code &
Try With Live Editor