Weather Observation Station 20

  • + 0 comments
    with ranked_latitude as (
        select 
             lat_n
            ,row_number() over (order by lat_n) as lat_ranking
            ,(select count(*) from station) as no_of_rows
            from station group by lat_n
    ),
        median as (
            select lat_ranking from ranked_latitude
            where lat_ranking = (
                case
                    when (no_of_rows)%2=0 then (no_of_rows+1)/2
                    else (no_of_rows+1)/2
                end
            )
        )
        select round(lat_n,4) from ranked_latitude where 
        lat_ranking = (select * from median);