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.

Comments

Popular posts from this blog

How to retrieve texts from Html SharePoint List source in Power BI

Simplifying Data Migration: Debezium for Moving Data from Oracle to SQL Server

Installing MariaDB on Ubuntu using SUDO