What's the most efficient way to implement this for a table with 5 million rows?

I'm introducing a new field named "CumulativePayments" it should be populated using this formula:

CumulativePayments = Payment on current row + SUM(Payment) (for all previous rows where A+B+C+D+E is the same as on the current row)

A,B,C,D,E are all varchar fields

Payment and CumulativePayment are MONEY type

there is an identity column (id) that can be used to identify previous rows i.e. id is less than current row id

**View Complete Post**

## Show grand total running total in GridView Footer