# HackerRank Solution in MySql

HackerRank Solution :- Weather Observation Station 18

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 Western Longitude (LONG_W in STATION).

Query the Distance between points p1 and p2 and 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.

Basic numeric functions to learn before solving this problem-

ROUND() — This function rounds a number to a specific number of decimal places.

Syntax

ROUND(number, decimals)

ABS() -This function returns the absolute value of a number i.e positive number.

Syntax

ABS(number)

The Distance between points p1 and p2 on 2d plane

The distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 — x2| + |y1 — y2|

Solutions-

mysql-

`select round(abs(min(LAT_N) - max(LAT_N)) + abs(min(LONG_W) - max(LONG_W)),4) from STATION;`

We have similar problem in hackerrank-

# HackerRank Solution :- 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.

Input Format

The STATION table is described as follows:

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

Basic numeric functions to learn before solving this problem-

SQRT() — This function returns the square root of a number.

Syntax

SQRT(number)

POWER() — This function returns the value of a number raised to the power of another number..

Syntax

POWER(a.b)

The Euclidean Distance between points p1 (a,c) and p2 (b,d)

The distance between two points in the plane with coordinates (a,c) and (b,d) is

`√ (b- a) ² + (d - c) ²`

Solutions-

mysql-

`select round(SQRT(power((max(LAT_N))-(min(LAT_N)),2) + power((max(LONG_W))-(min(LONG_W)),2)),4) from STATION`