Prepare > SQL > Aggregation > Weather Observation Station 16

2023. 5. 18. 20:56HackerRank-My SQL

 

Weather Observation Station 16 | HackerRank

Query the smallest of STATION's Northern Latitudes that is greater than 38.7780, and round to 4 decimal places

www.hackerrank.com

 

문제


Query the smallest Northern Latitude (LAT_N) from STATION that is greater than 38.7780. Round your answer to 4 decimal places.

 

 

 

 

코드


SELECT ROUND(MIN(LAT_N), 4) FROM STATION
WHERE LAT_N > 38.7780;

 

 

 

 

노트


SELECT ROUND(LAT_N, 4) FROM STATION
WHERE LAT_N > 38.7780
ORDER BY LAT_N ASC
LIMIT 0,1;
  • 최솟값에 ORDER BY로 접근하기

 

 

 

두 번째 시도

SELECT ROUND(LAT_N, 4) FROM STATION
WHERE LAT_N = (SELECT MIN(LAT_N) FROM STATION WHERE LAT_N > 38.7780;
  • 첫 번째가 더 나은듯?