본문 바로가기

Algorithm/MySQL

[해커랭크(HackerRank)] Weather Observation Station 15 (MySQL)

문제

Query the Western Longitude (LONG_W) for the largest Northern Latitude (LAT_N) in STATION that is less than 137.2345.
Round your answer to 4 decimal places.

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 < 137.2345
ORDER BY lat_n DESC
LIMIT 1

 

풀이

  1. STATION 테이블의 LONG_W 조회
  2. 137.2345 이하인 가장 큰 LAT_N
    LAT_N을 내림차순으로 정렬하고, 최대값을 출력하기 위해 LIMIT 1
  3. 소수점 이하 4번째 자리수까지 반올림
반응형