T-SQL Tutorial

T-SQL PERCENTILE_DISC


The T-SQL PERCENTILE_DISC function is an analytic function and is used in SQL Server database to calculate a specific percentile for sorted values in an entire rowset.

PERCENTILE_DISC Syntax


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



PERCENTILE_DISC Example


select b.*,
PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY b.id)
OVER (PARTITION BY b.price) AS PercentDisc
from books b
order by PercentDisc;