Prepare > SQL > Aggregation > Weather Observation Station 17

2023. 5. 18. 21:12HackerRank-My SQL

 

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

 

문제


Query the Western Longitude (LONG_W)where the smallest Northern Latitude (LAT_N) in STATION is greater than 38.7780. Round your answer to 4 decimal places.

 

=> 38.7780 이상인 LAT_N의 최솟값을 가진 LONG_W를 쿼리하라.

 

 

코드


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

 

 

 

 

노트


SELECT ROUND(LONG_W, 4) FROM STATION
WHERE LAT_N = 
(SELECT MIN(LAT_N) FROM STATION WHERE LAT_N > 38.7780);
  • 서브쿼리를 이용한 코드

 

SELECT ROUND(LONG_W, 4) FROM (SELECT * FROM STATION WHERE LAT_N > 38.7780) AS K
ORDER BY LAT_N
LIMIT 1;