Saturday 20 July 2024

PERCENTILE_DISC in SQL server

The SQL PERCENTILE_DISC will calculate a percentile of the sorted values within an entire row set, or within the partitions in a table. Basically, it returns the first value in the set whose ordered position is the same or more than the specified fraction. When we call PERCENTILE_DISC () we specify the percentile to use. It then performs its calculation based on that percentile.

Syntax 

 Percent to find: value of this is 0.0 to 1.0

Example

SELECT COUNT(*) NumberOfOrders, Month(OrderDate) AS orderMonth,

PERCENTILE_DISC(.5) WITHIN GROUP (ORDER BY COUNT(*))

OVER() AS PercentileDisc

FROM Sales.SalesOrderHeader

WHERE OrderDate >= '2013-01-01' AND OrderDate < '2014-01-01'

GROUP BY Month(OrderDate);

 


No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts