www.hackerrank.com/challenges/weather-observation-station-19/problem
Answer
select round(sqrt(power(max(lat_n) - min(lat_n),2) + power(max(long_w) - min(long_w),2)),4)
from station
www.hackerrank.com/challenges/weather-observation-station-20/problem
Answer - 중앙값 구현하기
MySQL은 중앙값을 지원하지 않아서 따로 구현해야 한다.
set @rownum = -1;
select round(avg(lat_n),4) as median
from (select @rownum := @rownum + 1 as rownumber, lat_n
from station
order by lat_n) as d
where rownumber in (ceil(@rownum / 2), floor(@rownum / 2))
참고로 오라클은 중앙값 기능을 지원한다!
728x90
반응형
'SQL & DB > HackerRank SQL Problem' 카테고리의 다른 글
[HackerRank SQL] Top Competitors (0) | 2021.03.01 |
---|---|
[HackerRank SQL] The Report (0) | 2021.03.01 |
[HackerRank SQL] Weather Observation Station 17, 18(MySQL) (0) | 2021.03.01 |
[HackerRank SQL] Weather Observation Station 15, 16(MySQL) (0) | 2021.03.01 |
[HackerRank SQL] Weather Observation Station 13, 14(MySQL) (0) | 2021.03.01 |