We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
SELECT
ROUND(
SQRT(POW(MAX(LAT_N) - MIN(LAT_N), 2) + POW(MAX(LONG_W) - MIN(LONG_W), 2)),
4
) AS Euclidean_Distance
FROM STATION;
Explanation:
MIN(LAT_N): This gets the minimum value of Northern Latitude.
MAX(LAT_N): This gets the maximum value of Northern Latitude.
MIN(LONG_W): This gets the minimum value of Western Longitude.
MAX(LONG_W): This gets the maximum value of Western Longitude.
The POW function is used to square the differences between the respective coordinates.
The SQRT function calculates the square root of the sum of the squared differences to get the Euclidean distance.
ROUND(..., 4): This rounds the final distance to 4 decimal places.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 19
You are viewing a single comment's thread. Return to all comments →
SELECT ROUND( SQRT(POW(MAX(LAT_N) - MIN(LAT_N), 2) + POW(MAX(LONG_W) - MIN(LONG_W), 2)), 4 ) AS Euclidean_Distance FROM STATION;
Explanation: MIN(LAT_N): This gets the minimum value of Northern Latitude. MAX(LAT_N): This gets the maximum value of Northern Latitude. MIN(LONG_W): This gets the minimum value of Western Longitude. MAX(LONG_W): This gets the maximum value of Western Longitude. The POW function is used to square the differences between the respective coordinates. The SQRT function calculates the square root of the sum of the squared differences to get the Euclidean distance. ROUND(..., 4): This rounds the final distance to 4 decimal places.