0
votes

The Table "Cric_Team" looks like this

When I execute the below query in SQL Server 2012, the 'unbounded following' is not calculating the sum upto last row of that partition. But, as per the definition, it should calculate upto last row from the current row.

SELECT Cric_Id,Cric_First_Name,Cric_Last_Name,Cric_Role ,Runs,Centuries ,Fifty AS Fifties,Ducks,SUM(Ducks) OVER ( PARTITION BY Cric_Role ORDER BY Ducks RANGE BETWEEN current row AND unbounded following ) AS Total_Ducks FROM Cric_Team

The Screenshot of table after executing the query

1

1 Answers

0
votes

How about using a descending sort instead? Do this do what you want?

SELECT Cric_Id, Cric_First_Name, Cric_Last_Name, Cric_Role, Runs,
       Centuries, Fifty AS Fifties, Ducks,
       SUM(Ducks) OVER ( PARTITION BY Cric_Role ORDER BY Ducks DESC) AS Total_Ducks  
FROM Cric_Team;