A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to decimal places.
풀이
제출한 답
with sub as (
select *, row_number() over (order by lat_n) rw, count(*) over () cnt
from station)
select round(avg(lat_n),4)
from sub
where case when mod(cnt,2) = 1 then rw = (cnt+1)/2
else rw in (cnt/2, (cnt/2)+1) end
-> 갯수는 cnt, 행 번호는 rw, 갯수가 짝수일 때는 두 값을 평균내야 함
'데이터 분석 > SQL 연습문제' 카테고리의 다른 글
Placements (HackerRank) (0) | 2023.03.28 |
---|---|
262. Trips and Users (LeetCode) (0) | 2023.03.27 |
Weather Observation Station 11 (HackerRank) (0) | 2022.11.06 |
Ollivander's Inventory (HackerRank) (0) | 2022.11.05 |
SQL Project Planning (HackerRank) (0) | 2022.11.04 |
댓글