MEDIAN [Analytic]

For each row, returns the median value of a value set within each partition. MEDIAN determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that data type, and returns that data type.

MEDIAN is an alias of PERCENTILE_CONT [Analytic] with an argument of 0.5 (50%).

Behavior Type

Immutable

Syntax

MEDIAN ( expression ) OVER ( [ window‑partition‑clause ] ) 

Parameters

expression

Any NUMERIC data type or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the middle value or an interpolated value that would be the middle value once the values are sorted. Null values are ignored in the calculation.

OVER()

If the OVER clause specifies window‑partition‑clause, MEDIAN groups input rows according to one or more columns or expressions. If this clause is omitted, no grouping occurs and MEDIAN processes all input rows as a single partition.

Examples

See Calculating a Median Value