Ecco un modo per farlo con un CTE invece di un cursore:
WITH Base AS
(
SELECT ROW_NUMBER() OVER (ORDER BY [Count] DESC) RowNum,
[Dept],
[Count]
FROM SR
)
SELECT SR.Dept, SR.Count, SUM(SR2.[Count]) Total
FROM Base SR
INNER JOIN Base SR2
ON SR2.RowNum <= SR.RowNum
GROUP BY SR.Dept, SR.Count
ORDER BY SR.[Count] DESC
Nota che questo è l'ordine decrescente Count
come fa il risultato del tuo campione. Se c'è qualche altra colonna che non è mostrata che dovrebbe essere utilizzata per l'ordine, sostituisci semplicemente Count
in ciascuno dei ORDER BY
clausole.