MEDIAN
functionsupportedCore SQL functionsDetermines the median of a set of values.
Syntax
supportedpartialnot supportednot scored
Aggregate function
MEDIAN( <expr> )
Window function
MEDIAN( <expr> ) OVER ( [ PARTITION BY <expr2> ] )
Returns
Returns a FLOAT or DECIMAL (fixed-point) number, depending upon the input.
Usage notes
- If the number of non-NULL values is an odd number greater than or equal to 1, this returns the median (“center”) value of the non-NULL values.
- If the number of non-NULL values is an even number, this returns a value equal to the average of the two center values. For example, if the values are 1, 3, 5, and 20, then this returns 4 (the average of 3 and 5).
- If all values are NULL, this returns NULL.
- If the number of non-NULL values is 0, this returns NULL.
- DISTINCT is not supported for this function.
- When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.
- Explicit window frames.
Argument
expr: The expression must evaluate to a numeric data type (INTEGER, FLOAT, DECIMAL, or equivalent).