Running Total In SQL Server

Running total refers to the sum of values in all cells of a column that precedes the next cell in that particular column.


Using Window Function

Assuming, the table has 2 columns, col1 is primary key with data type integer and col2 is integer data type values. To calculate running total on col2 write a query as

select col1, col2,sum(col2) over(order by col1) as runnintotal from tablename

using window function is more performance efficient.

Running Total In SQL Server

Running total refers to the sum of values in all cells of a column that precedes the next cell in that particular column. Using Window Funct...