SQL/HackerRank
[해커랭크 easy] Weather Observation Station 17(MySQL)
강떡볶
2022. 3. 16. 13:56
https://www.hackerrank.com/challenges/weather-observation-station-17/problem?isFullScreen=true
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
내가 풀었던 방법 ▼
select round(long_w, 4)
from station
where lat_n = (select min(lat_n) as min from station where lat_n >38.7780)
이렇게 where절에 서브쿼리를 넣어줬다.
근데 서브쿼리를 안넣고 풀고 있을지도 궁금해서 다른 사람 풀이를 찾아봤다.
select round(long_w, 4)
from station
group by lat_n, long_w
having lat_n > 38.778
order by lat_n
limit 1
이렇게 group by 절로 lat_n과 long_w를 같이 묶어준 후
having을 이용해 필터링하는 방법도 있다.