16.20 - MEDIAN - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantageā„¢ Time Series Tables and Operations

Teradata Database
Teradata Vantage NewSQL Engine
Release Number
March 2019
Content Type
Programming Reference
Publication ID
English (United States)
Last Update


Returns the median of all values in each group. MEDIAN returns the average of the two middle values if the value_expression contains an even number of values. It is a single-threaded function.

To invoke the time series version of this function, use the GROUP BY TIME clause. For more information, see GROUP BY TIME Clause.


Syntax Elements

All non-null value_expressions, including duplicates.
Excludes duplicates specified by value_expression.
A literal or column expression for which a median is to be computed.

The value_expression cannot be a reference to a view column derived from a function, and cannot contain any ordered analytical or aggregate functions.

Return Values

This function returns the REAL data type.

Nulls are not included in the result computation.

Usage Notes

The ALL keyword includes all non-null value_expressions, including duplicates in the computation. The DISTINCT keyword excludes duplicates specified by value_expression from the computation.
  • MEDIAN is valid only for numeric data.
  • DISTINCT is only valid with MEDIAN when using the time series version of MEDIAN. MEDIAN DISTINCT queries return an error if not associated with a GROUP BY TIME clause.