MEDIAN() GROUP BY ...

All functions > GROUP BY > MEDIAN() GROUP BY ...

Returns the median of the values in the group as DOUBLE.

Syntax

MEDIAN(expr)
 [ FILTER (WHERE condition) ]
  [ GROUP BY feature [, feature ...] ]

Notes

  • NULL values are ignored where the underlying aggregate skips NULLs
  • Can be used with FILTER (WHERE condition) and GROUP BY like other aggregates

Examples

FeatureQL
-- Median over one group
RETURN
    f1 := ZIP(ARRAY(1, 1, 1) AS g, ARRAY(1e0, 2e0, 9e0) AS x).TRANSFORM(
        DEFINE
            p := MEDIAN(x) GROUP BY (g)
        RETURN p
    ).UNWRAP_ONE()
;
Result
f1 DECIMAL
2.0