Weather Observation Station 20

  • + 1 comment

    SET @ec = (SELECT COUNT(lat_n) FROM station);

    WITH med AS (Select * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY Lat_n) as rn, Lat_n, LEAD(lat_n,1) OVER (ORDER BY lat_n) as x FROM Station ) AS temp WHERE rn=(CEILING(@ec/2)) ) SELECT case WHEN @ec%2=1 THEN ROUND(lat_n,4) WHEN @ec%2=0 THEN ROUND((lat_n+x)/2,4) END FROM med

    ;