일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 그로스해킹
- TRUNCATE
- MySQL
- SQL
- not in
- Round
- pandas
- 머신러닝
- solvesql
- 파이썬
- hackerrank
- airflow.cfg
- GROUPBY
- 전처리
- SUM
- having
- PostgreSQL
- 다중 JOIN
- SQLite
- Limit
- 프로그래머스
- 결측값
- seaborn
- 데이터분석
- 데이터리안 웨비나
- airflow 설치
- Oracle
- matplotlib
- 데이터시각화
- join
- Today
- Total
Milky's note
[HackerRank](M) Weather Observation Station 18 본문
https://www.hackerrank.com/challenges/weather-observation-station-18/problem?isFullScreen=true
Weather Observation Station 18 | HackerRank
Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.
www.hackerrank.com
[문제]
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 Manhattan Distance between points P1 and P2 and round it to a scale of 4 decimal places.
Manhattan Distanc : In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|.

Input Format
The STATION table is described as follows:

[답]
- mysql
select round(abs(a-c)+abs(b-d),4) from
(select min(lat_n) a, min(long_w) b, max(lat_n) c, max(long_W) d from station) p
두 점사이의 거리를 맨하탄 거리 공식을 사용해서 구하고 소수 4째자리까지 반올림으로 나타내는 문제이다.
맨하탄 공식이 뭐야 했는데 친절하게 알려주었다.
|x1 - x2| + |y1 - y2| 다음과 같은 공식을 사용한다.
절대값 함수가 필요해보인다. (절대값 : abs(컬럼))
물론 바로 풀어도 되지만 이중 select를 사용해서 alias로 간단한 풀이로 문제를 풀었다.
'SQL > SQL 코딩 테스트-HackerRank' 카테고리의 다른 글
[HackerRank](M) Weather Observation Station 20 (0) | 2022.03.28 |
---|---|
[HackerRank](M) Weather Observation Station 19 (0) | 2022.03.28 |
[HackerRank](M) New Companies (0) | 2022.03.28 |
[HackerRank](E) Draw The Triangle 2 (0) | 2022.03.26 |
[HackerRank](E) Draw The Triangle 1 (0) | 2022.03.26 |