MEDIAN

The MEDIAN function counts the statistical median - an order statistic that gives the middle value of a sample. If the middle falls between two values, the function returns average of the two middle values. Null values are ignored.

The MEDIAN function is especially useful in cases where a small set of outliers could drastically skew the average if calculated as a mean. MEDIAN can be used to aggregate facts in the same way as SUM, MAX, MIN, or AVG, but it also accepts metrics or entire metric expressions as arguments.

Syntax

SELECT MEDIAN(…)
MEDIAN(fact)
MEDIAN(metric)
MEDIAN(metric_expression)

Examples

SELECT MEDIAN(Cost) BY ALL OTHER
SELECT MEDIAN(Date (Closed) - Date (Opened)) BY Ticket_ID
SELECT MEDIAN(Payment) BY Customer FOR PREVIOUS(Month)