MEDIAN(numeric_exp)

Returns the Median Value of the population of numeric_exp.

Description

The median is used to indicate the center of a given population at the point where the distribution of scores is divided in half. Given a population of "n":

If n is odd, the median is the middle data elements of the sorted list of values.

If n is even, the median is the average of the data element between the middle data elements.

 

Example:

With a resultset of the following four values (v1, v2, v3, v4), the median would be the average (or mean) of values v2 and v3.

v1

v2

v3

v4

5

20

30

50

The median would be 25.

 

Parameters

numeric_exp must be a number, or a numeric expression.

 

Note: If the number of data points is less than QUANTILE_ESTIMATION_THRESHHOLD, then the calculation for a median or quantile will proceed as follows:

 

  1. If the data is not sorted on any columns for which calculation is requested, the data will be sorted.

  2. The quantile position is calculated by linear interpolation.

 

If the number of data points is greater than or equal to QUANTILE_ESTIMATION_THRESHHOLD, then the calculation for a median or quantile will proceed as follows:

The quantile position will be estimated by the linear time selection algorithm "Randomized-Select" as described in Introduction to Algorithms by Cormen, Leiserson, and Rivest, p. 187.