SQL Flow Field Guide

APPROX_PERCENTILE_DISC

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

ordered-set approximate aggregate

What changes

Input
ordered values of each group (WITHIN GROUP)
Output or change
approximate percentile value from the set
Return type
The return type is determined by the order_by_expression type.

Syntax at a glance

APPROX_PERCENTILE_DISC (numeric_literal) WITHIN GROUP (ORDER BY order_by_expression [ASC|DESC])

Work example

Estimate a discrete percentile that returns an observed input value.

Check the input ordering type and compare the approximate threshold with an exact sample.

Check your work The returned value is an observed value and the percentile estimate is approximate.

Open Microsoft Learn for full syntax, permissions, and details for your version.