MEDIAN returns the average of the two middle values.
Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<value> | The expression used to calculate the median value. | DOUBLE PRECISION, REAL, BIGINT, INT |
<condition> | An optional boolean expression to filter rows used in aggregation | BOOL |
Return Type
MEDIAN returns a value of type DOUBLE PRECISION.
- This function ignores
NULLvalues. - If the input is empty, the function returns
NULL.
Examples
Example The following query usesUNNEST to convert an array [1,2,5] into a column, calculates the median value, and returns it as result:
| result (DOUBLE PRECISION) |
|---|
| 2 |
UNNEST to convert an array [100, NULL, 1, 2, 5] into a column, calculates the median value, and returns it as result:
| result (DOUBLE PRECISION) |
|---|
| 3.5 |
NULL elements is even after ignoring NULL values. The average of the middle elements, 2 and 5, is calculated as : ((2+5)/2).