CUME_DIST() OVER ...

All functions > WINDOW FUNCTION > CUME_DIST() OVER ...

Returns the cumulative distribution: (number of rows <= current row) / (total rows).

Syntax

CUME_DIST() [WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Returns a value between 0 (exclusive) and 1 (inclusive)
  • Requires ORDER BY clause to determine row ordering
  • PARTITION BY creates independent distribution groups

See also

Examples

FeatureQL
-- Cumulative fraction of rows at or before current value
RETURN
    f1 := ZIP(ARRAY(1, 2, 3) AS id, ARRAY(10, 20, 30) AS v).TRANSFORM(
        RETURN CUME_DIST() OVER (ORDER BY v ASC).ROUND(2)
    ).UNWRAP()
;
Result
f1 ARRAY<DOUBLE>
[0.33, 0.67, 1.00]