Anusha Murali

Logo

Please see github.com/anusha-murali for all of my repositories.

View GitHub Profile

34. Weather Observation Station 19: Solution


Consider $P_1(a, c)$ and $P_2(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 $P_1$ and $P_2$ and format your answer to display 4 decimal digits.

The STATION table is described as follows:

16

where LAT_N is the northern latitude and LONG_W is the western longitude.

solution_image5

We first find $a, b, c,$ and $d$ by selecting MIN(LAT_N), MAX(LAT_N), MIN(LONG_W), and MAX(LONG_W) from STATION in an inline view (aliased IV), and then use these quantities in the outer query to compute the Euclidean distance as follows:

SELECT ROUND(SQRT((b-a)*(b-a) + (d-c)*(d-c)), 4)
FROM
(SELECT MIN(LAT_N) a, MAX(LAT_N) b, MIN(LONG_W) c, MAX(LONG_W) d FROM STATION) IV;

Back to problems


anusha-murali.github.io