percentile(expression: numeric or duration, percentile: const numeric) -> expression

percentile(expression, p) computes an approximate percentile of expression over each group, where p is a compile-time constant between 0 and 1 inclusive. Inputs may be numeric or duration or timestamp; for plain numeric inputs the aggregated result is float64, while duration and timestamp results keep the corresponding temporal type. The estimate is not exact and can differ from exact order-statistic functions. You may use percentile inside window with explicit group_by, order_by, and usually frame; without an explicit frame the implicit query window frame applies and the pipeline may be flagged as not accelerable. percentile cannot be combined with a frame that uses only start or end range bounds; those frames are limited to a small set of basic aggregates.

Domain

This is an aggregate function (aggregates rows over a group in aggregate verbs).

This is a window function (calculates over a group of multiple input rows using windowing).

Categories

Examples

aggregate p95:percentile(latency_ms, 0.95), group_by(route)

Computes an approximate 95th percentile of latency per route in a grouped aggregate.

make_col roll_p99:window(percentile(latency_ms, 0.99), group_by(host), order_by(valid_from), frame(back:5m))

Shows percentile evaluated inside window with explicit partition, ordering, and five-minute frame.