Weather Observation Station 5

  • + 0 comments

    To calc the median For even number..

    EX: 2 4 5 (6 7) 8 10 12 order ASC 1 2 3 4 5 6 7 8

    total Number of them is 8....the median=(Number(n/2)+Number(n/2)+1)/2

    say the data set count=500 instead of 499

    Number(n/2)=250 Number(n/2)+1=251

    then you get the average:

    WITH CTE AS (SELECT TOP(2) CASE WHEN ROW_NUMBER() OVER(ORDER BY LAT_N )=250 OR ROW_NUMBER() OVER(ORDER BY LAT_N )=251 THEN ROUND(CONVERT(DECIMAL(10, 4), LAT_N), 4) END AS M FROM STATION ORDER BY M DESC)

    SELECT ROUND(CONVERT(DECIMAL(10, 4), AVG(M)), 4) FROM CTE WHERE M IS NOT NULL