출처
문제 18
Consider p1(a,b) and 소2(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 Manhattan Distance between points and and round it to a scale of decimal places.
문제에 대한 해석
a LAT_N 최소값
b LONG_W 최소값
c LAT_N 최대값
d LONG_W 최대값
맨파튼 거리
풀이(MYSQL)
SELECT
round(ABS(MIN(lat_n)-MAX(lat_n))
+ ABS(MIN(long_w)-MAX(long_w)),4)
FROM STATION
출처
문제 19
Consider p1(a,b) and p2(c,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.
문제에 대한 해석
p1(a,b) = LAT_N의 최소값, LAT_N의 최대값
p2(c,d) = LONG_W 의 최솟값, LONG_W 의 최대갑p1 과 p2의 유클리드 거리를 계산
풀이(MYSQL)
SELECT
ROUND(SQRT(
POWER(MIN(lat_n)-MAX(lat_n),2)
+ POWER(MIN(long_w)-MAX(long_w),2)),4)
FROM STATION
배운점
- 절댓값: abs(대상숫자)
- 제곱근 : sqrt(대상숫자)
- 거듭제곱 : power(대상숫자, 거듭제곱할 횟ㄱ수)
'문제풀이 > SQL(My sql)' 카테고리의 다른 글
[문제풀이] Hacker Rank - Weather Observation Station 20 (0) | 2024.06.10 |
---|---|
[문제풀이] Hacker Rank - Binary Tree Nodes (1) | 2024.06.10 |
[문제풀이] Hacker Rank - Weather Observation Station 17 (0) | 2024.06.07 |
[문제풀이] Hacker Rank - The Blunder (0) | 2024.06.07 |
[문제풀이] Hacker Rank - Top Earners (0) | 2024.06.07 |