| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
- Oracle
- SQLite
- airflow.cfg
- pandas
- having
- 데이터리안 웨비나
- 프로그래머스
- 머신러닝
- hackerrank
- 다중 JOIN
- SQL
- PostgreSQL
- Limit
- 데이터시각화
- TRUNCATE
- airflow 설치
- matplotlib
- seaborn
- GROUPBY
- MySQL
- SUM
- 결측값
- 그로스해킹
- Round
- 파이썬
- not in
- 데이터분석
- join
- solvesql
- 전처리
- Today
- Total
Milky's note
[HackerRank](M) Weather Observation Station 19 본문
https://www.hackerrank.com/challenges/weather-observation-station-19/problem?isFullScreen=true
Weather Observation Station 19 | HackerRank
Query the Euclidean Distance between two points and round to 4 decimal digits.
www.hackerrank.com
[문제]
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.
[답]
- mysql
select round(sqrt(pow((a-b),2)+pow((c-d),2)),4) from
(select min(lat_n) a, max(lat_n) b, min(long_W) c, max(long_W) d from station) p
이번엔 유클리디안 거리 공식을 사용해서 두 점사이의 거리를 구해주는 문제이다.
유클리디안은 공식은 위에 첨부한 내용과 같다.
먼저 P1(a,c) P2(b,d)가 있고 (a-b)의 제곱을 하고 (c-d)의 제곱을 해준 뒤 더해준다.
제곱을 하는 함수가 필요하다. (제곱 함수 : pow(컬럼, 제곱수))
해당 문제는 2제곱을 하면 되어서 제곱 수 파라미터에 2를 입력해준다.
다음으로 제곱하여 더한 수에 제곱근(루트)를 해준다.
제곱근을 해주는 함수가 필요하다. (제곱근 함수 : sqrt(컬럼))
제곱근까지 되었으면 round를 사용해서 소수점 4째 자리수까지 나타내고 반올림을 해준다.
제곱과 제곱근 함수를 사용하는 문제이다.
'SQL > SQL 코딩 테스트-HackerRank' 카테고리의 다른 글
| [HackerRank](M) Contest Leaderboard (0) | 2022.03.30 |
|---|---|
| [HackerRank](M) Weather Observation Station 20 (0) | 2022.03.28 |
| [HackerRank](M) Weather Observation Station 18 (0) | 2022.03.28 |
| [HackerRank](M) New Companies (0) | 2022.03.28 |
| [HackerRank](E) Draw The Triangle 2 (0) | 2022.03.26 |