SQL 문제풀이

[해커랭크 SQL] Aggregation - Weather Observation Station 17

냄비짱 2023. 8. 25. 18:00
728x90

❓ Question
https://www.hackerrank.com/challenges/weather-observation-station-17

 

Weather Observation Station 17 | HackerRank

Query the Western Longitude for the smallest value of the Northern Latitudes greater than 38.7780 in STATION and round to 4 decimal places.

www.hackerrank.com

❗ Answer

SELECT ROUND(long_w,4)
    FROM station
    WHERE lat_n = (SELECT MIN(lat_n)
                    FROM station
                    WHERE lat_n > 38.7780);

📌 Discussion

  • sub query scalar로 lat_n > 38.7780인 레코드 중 lat_n의 최솟값을 추출한다.
  • lat_n이 최솟값일 때의 long_w를 반올림하여 소수점 넷째자리까지 추출