# med

Median

Syntax: med x, med[x]

Where x is a numeric list returns its median.

q)med 10 34 23 123 5 56
28.5
q)select med price by sym from trade where date=2001.10.10,sym inAAPLLEH


med is an aggregate function.

## Partitions and segments

In V3.0 upwards med signals a rank error when running a median over partitions, or segments. This is deliberate, as previously med was returning median of medians for such cases. This should now be explicitly coded as a cascading select.

q)select med price by sym from select price, sym from trade where date=2001.10.10, sym in AAPLLEH


Basics: Mathematics