MEDIAN returns the average of the two middle values.
Syntax
Parameters
Return Type
MEDIAN returns a value of type DOUBLE PRECISION.
- This function ignores
NULLvalues. - If the input is empty, the function returns
NULL.
Examples
The following example calculates the median of three values. Since the number of elements is odd, the middle element is returned directly:Rows: 1Execution time: 6.04ms
NULL elements is even, MEDIAN returns the average of the two middle values. NULL values are ignored before the median is calculated:
Rows: 1Execution time: 6.46ms
NULL, the non-null values are [1, 2, 5, 100]. The two middle elements are 2 and 5, so the result is calculated as: ((2+5)/2).