[HackerRank MySQL] Weather Observation Station 19 - POWER & SQRT (SQL에서 제곱과 제곱근 계산하기)

2021. 2. 15. 22:58Today I Learned.../MySQL

Weather Observation Station 19

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.

Euclidean Distance

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(sqrt(power(max(lat_n)-min(lat_n), 2)+power(max(long_w)-min(long_w), 2)), 4)
from station

POWER & SQRT in SQL (SQL에서 제곱과 제곱근 계산하기)

  Syntax Example
Power / Involution (거듭제곱) POWER(base, exponent) POWER(2, 3) → 8
Square Root (제곱근) SQRT(numeric value) SQRT(25) → 5

Reference: HackerRank Practice > SQL > Aggregation > Weather Observation Station 19