본문 바로가기
MySQL/문제풀이

[HackerRank] Weather Observation Station 3 / Weather Observation Station 19

by MINNI_ 2021. 3. 23.

1) Weather Observation Station 3


1. 문제

 

Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
The STATION table is described as follows:

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


2. 답

SELECT DISTINCT city
FROM station
WHERE id % 2 = 0

3. KEY POINT

 

  • 짝수 표현 방법 : 1. n % 2 = 0 
                          2. MOD(n, 2) = 0

 

www.hackerrank.com/challenges/weather-observation-station-3/problem?h_r=internal-search

 

Weather Observation Station 3 | HackerRank

Query a list of unique CITY names with even ID numbers.

www.hackerrank.com


 

2) Weather Observation Station 19


1. 문제

 

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  and  and format your answer to display  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.

 

더보기

[ 정의: Euclidean Distance ]

 

In the Euclidean plane, let point p have Cartesian coordinates (p1, p2) and let point q have coordinates (q1, q2). 
Then the distance between p and q is given by

2. 답

SELECT ROUND(SQRT(POW(MIN(lat_n) - MAX(lat_n), 2) + POW(MIN(long_w) - MAX(long_w), 2)), 4)
FROM station

3. KEY POINT

 

  • POW(컬럼명/값, n) : 값을 n 제곱해서 반환
  • SQRT(컬럼명/값) : 값의 제곱근을 반환

 

www.hackerrank.com/challenges/weather-observation-station-19/problem?h_r=internal-search

 

Weather Observation Station 19 | HackerRank

Query the Euclidean Distance between two points and round to 4 decimal digits.

www.hackerrank.com

댓글