median calc?

  • Does anyone know how to calculate the median of a column of figures.

    I have a column which is derived from a datediff and result shown as minutes in a view.

    I know via Excel that the MEDIAN for the following is 12.5. HOw would I express this in SQL

    Thanks in advance for any help

    CREATE TABLE PS_TestForOnline

    (

    number NVARCHAR (20),

    );

    INSERT INTO PS_TestForOnline

    VALUES('1' );

    INSERT INTO PS_TestForOnline

    VALUES('5' );

    INSERT INTO PS_TestForOnline

    VALUES('10' );

    INSERT INTO PS_TestForOnline

    VALUES('15' );

    INSERT INTO PS_TestForOnline

    VALUES('20' );

    INSERT INTO PS_TestForOnline

    VALUES('999' );

    SELECT * FROM PS_TestForOnline

    DROP TABLE PS_TestForOnline

    Paul

  • http://msdn.microsoft.com/en-us/library/bb395166(v=sql.90).aspx

    Search for median. It's about a 3rd of the way in.

  • Many Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply