Saturday 20 July 2024

Cume_dist() function in SQL server

Calculate the cumulative distribution of value in the result set. It represent the proportion of rows that are less than or equal to the current row. Below formula used inside this function. 

Syntax

Example

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

RANK() OVER(ORDER BY COUNT(*)) AS Ranking,

CUME_DIST() OVER(ORDER BY COUNT(*)) AS CumeDist

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