You are viewing an older version of this section. View current production version.
Join the MemSQL Community Today
Get expert advice, develop skills, and connect with others.

MEDIAN

It is an aggregate function that returns the median of an expression (middle value in a sorted data set), which separates the higher half in a distribution from the lower half.

Syntax

MEDIAN ( expression )

Arguments

  • expression: Any numeric expression.

Return Type

Numeric value.

Examples

INSERT INTO T4 (a,b) VALUES (1,1),(1,2),(1,3),(2,1),(2,3),(2,5);

SELECT a, MEDIAN(b) FROM T4 GROUP BY a ORDER BY a;
****
+------+-----------+
| a    | MEDIAN(b) |
+------+-----------+
|    1 |    2.0000 |
|    2 |    3.0000 |
+------+-----------+