Computes a specific percentile for sorted values in an entire rowset or within distinct partitions of a rowset. For a given percentile value P, PERCENTILE_DISC sorts the values of the expression in the ORDER BY clause and returns the value with the smallest CUME_DIST value (with respect to the same sort specification) that is greater than or equal to _P_. For example, PERCENTILE_DISC (0.5) will compute the 50th percentile (that is, the median) of an expression. PERCENTILE_DISC calculates the percentile based on a discrete distribution of the column values; the result is equal to a specific value in the column.


PERCENTILE_DISC ( numeric_literal ) WITHIN GROUP ( ORDER BY order_by_expression [ ASC | DESC ] )
           OVER ( [ <partition_by_clause> ] )



The percentile to compute. The value must range between 0.0 and 1.0.

Return types#

The return type is determined by the order_by_expression type.


SELECT PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY [IntColumn]) OVER() AS [ReturnValuePercentileDisc]
  FROM [IntTable]

See Also#