QUANTILE_CONT() OVER ...

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

Returns the continuous quantile of the window at the given probability; result type is DOUBLE.

Syntax

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

Notes

  • SQL translation is implemented only when the current SQL backend is DuckDB
  • Requires a well-defined window (ORDER BY, and optionally PARTITION BY and frame)
  • NULL values are ignored where the underlying window aggregate skips NULLs
  • Use a DOUBLE value expression (for example 10e0) so translation matches the DOUBLE quantile argument

Availability

Available on DuckDB. Not available on Trino, Serving.

See also

Examples

FeatureQL
-- Running continuous 0.5 quantile
-- Continuous 0.5 quantile counting only rows where v > 15 (10 and 5 excluded from the frame)
RETURN
    f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN QUANTILE_CONT(v::DOUBLE, 0.5e0) OVER (ORDER BY id ASC).ROUND(2)
    ).UNWRAP(),
    f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN QUANTILE_CONT(v::DOUBLE, 0.5e0) FILTER (WHERE v > 15) OVER (
            ORDER BY id ASC
        ).ROUND(
            2
        )
    ).UNWRAP()
;
Result
f1 ARRAY<DOUBLE>f2 ARRAY<DOUBLE>
[30.00, 20.00, 20.00, 15.00][30.00, 30.00, 25.00, 25.00]