Skip to main content

Categories: Aggregate, Percentile

MEDIAN

Computes the median of a numeric column. Equivalent to PERCENTILE_CONT(0.5). Interpolates between the two middle values for even-sized datasets.

Syntax​

MEDIAN(num_col numeric) → double precision​

  • num_col: A numeric column or expression whose median value you want to compute.

Examples

MEDIAN example
SELECT MEDIAN(pop) FROM Samples."samples.dremio.com"."zips.json"
-- 2783.0
Calculate the median of an odd number of values
SELECT MEDIAN(v) FROM (VALUES (1), (2), (3), (4), (5)) AS t(v)
-- 3.0
Calculate the median of an even number of values
SELECT MEDIAN(v) FROM (VALUES (10), (20), (30), (40)) AS t(v)
-- 25.0
Calculate the median with a NULL value
SELECT MEDIAN(v) FROM (VALUES (1), (NULL), (3)) AS t(v)
-- 2.0

Usage Notes​

Use only with numeric data types. Dremio ignores NULL values in the specified column.