Oracle

HackerRank - Weather Observation Station 15

HS DEVELOG 2024. 12. 18. 09:26

 

 

Prepare - SQL - AggregationWeather - Observation Station 15

 

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  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.

문제는 LAT_N이 137.2345 보다 작은 것들 중에서 가장 큰 LONG_W를 뽑아서 보여주는 것이다.

 

Oracle

SELECT ROUND(LONG_W, 4)
FROM (SELECT *
    FROM STATION
    WHERE LAT_N < 137.2345
    ORDER BY LAT_N DESC)
WHERE ROWNUM <= 1;

 

oracle에서는 따로 limit가 없기 때문에 서브 쿼리를 만들어서 순서대로 정렬까지 해주고, 내가 원하는 원소를 뽑는걸로 문제를 해결했다.