해커랭크 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 Manhattan Distance between points  P1 and P2 and round it to a scale of 4 decimal places.

2차원 평면상에서 P1(a,b),  P2(c,d) 두 점이 있음
a는 LAT_N의 최솟값
b는 LONG_W의 최솟값
c는 LAT_N의 최댓값
d는 LONG_W의 최댓값

두 점의 맨해튼 거리를 구하는 쿼리 입력, 그리고 결과는 소수점 4자리까지 반올림.

*맨해튼 거리(Manhattan Distance)
: 축을 따라 직각으로 측정된 두 점 사이의 거리  --> | x1 - x2 | +| y1 - y2 |
즉 이 문제에서는 | a - c | + | b - d |

Input Format

The STATION table is described as follows:

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

문제 풀이

SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)),4)
FROM station

풀이 순서

 

1. a = MIN(LAT_N)

   b = MAX(LAT_N)

   c = MIN(LONG_W)

   d = MAX(LONG_W)

 

2. | a - c | + | b - d |  계산

   절대값은 ABS 함수 사용

 

3. 반올림 ROUND  함수 사용

 

해커랭크 Weather Observation Station 17 문제 바로가기 

 

 

문제 해석

Query the Western Longitude(LONG_W)where the smallest Northern Latitude(LAT_N) in STATION is greater than 38.7780.
station 테이블에서 북위(LAT_N) 38.7780보다 큰 값 중에서 가장 작은 북위일 때, 서부경도의 값을 나타내는 쿼리를 입력

Round your answer to 4 decimal places.
반올림해서 소수점 4자리까지 나타내기.

Input Format

The STATION table is described as follows:

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

 

문제 풀이

SELECT ROUND(LONG_W, 4)
FROM station 
WHERE LAT_N > 38.7780
ORDER BY LAT_N ASC
LIMIT 1

SELECT ROUND(LONG_W, 4) -- LONG_W을 반올림해서 소수점4자리까지 나타냄
FROM station                       
WHERE LAT_N > 38.7780     -- 비교연산자와 WHERE 조건문 사용, 38.7780보다 큰 LAT_N
ORDER BY LAT_N ASC         -- LAT_N을 오름차순 정렬, 조건에 맞는 가장 낮은 값이 맨 위에 나타남
                                         (ASC는 생략 가능)
LIMIT 1                            -- 첫번째 데이터만 보기

해커랭크 Weather Observation Station 7 바로가기

 

Weather Observation Station 7 | HackerRank

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.

www.hackerrank.com

 

문제 해석

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.
--> STATION 테이블에서 모음으로 끝나는 도시(CITY)이름의 리스트를 뽑는 쿼리를 작성하라.

Your result cannot contain duplicates.
--> 결과에 중복된 것이 있으면 안된다. 

 

Input Format

The STATION table is described as follows:

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

 

문제 풀이

LIKE 사용 풀이

SELECT DISTINCT city
FROM station 
WHERE city LIKE '%a'
   OR city LIKE '%e'
   OR city LIKE '%i'
   OR city LIKE '%o'
   OR city LIKE '%u'

SELECT DISTINCT city   -- city 컬럼을 불러오되 중복을 피하기 위해 DISTINCT 사용
FROM station             
WHERE city LIKE '%a'    -- 조건문 WHERE 사용, '와일드카드 %'로 모음으로 끝나는 이름 조건, 
     OR city LIKE '%e'        논리연산자 OR사용으로 각 a,e,i,o,u 으로 끝나는 도시이름 모두 추출
     OR city LIKE '%i'
     OR city LIKE '%o'
     OR city LIKE '%u'

+ Recent posts