Puzzler: Finding median value with SQL?

From: Mcrider <mcrider_at_acca.nmsu.edu>
Date: 24 Mar 1994 22:04:58 GMT
Message-ID: <2mt2qaINNshc_at_dns1.NMSU.Edu>


How can one find a median value in Oracle? In a statistical distribution the median value is the value of the variate above and below which equal numbers of items lie.

As an example, assume we have a table containing a column of numbers that all fall within a certain range. If we could order all the values in the column and identify the value at the middle of the column, we would know the median value. We might suppose that we could simply make use of the 'ROWNUM' pseudo-column with the 'ORDER BY' clause in a 'SELECT' statement. However, the value of rownum is assigned *before* the 'ORDER BY' clause takes effect, so this method won't work.

Does anyone have a suggestion?

-- 
John Crain           mcrider_at_acca.nmsu.edu

AMA #653500          BMWMOA #41593
Received on Thu Mar 24 1994 - 23:04:58 CET

Original text of this message