MEDIAN
Description
This function calculates the median per group. Median can be applied to INT, FLOAT or DATE columns.
The median is the middle element of a group. If the group has an even number of elements, the higher value of the two middle values is taken as the median for INT and FLOAT data types. For DATE values, it takes the more recent date.
Syntax
MEDIAN ( table.column )
NULL handling
NULL values are ignored, so they do not influence the result. If all the values of a group are NULL, the result for this group is also NULL.
Examples
[1] Median of column with 3 rows. | ||||||||||
| ||||||||||
|
[2] Median of column with 4 rows. If a group has an even number of entries, the upper value of the two middle values is taken. | |||||||||||
| |||||||||||
|
[3] Get the median value by country. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|
[4] Get the median value mixed with nulls, grouped by country. | ||||||||||||||||||
| ||||||||||||||||||
|