How to do Running Total Formula in SQL Server

Pratik Thummar 21 Reputation points
2021-05-14T19:22:38.853+00:00

How to do Running Total Formula in SQL

Give Example..

![96760-image.png]1

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Guoxiong 8,206 Reputation points
    2021-05-14T19:46:30.887+00:00
    DECLARE @T TABLE (
        [User] varchar(10),
        [Total] int
    );
    INSERT INTO @T([User], [Total]) VALUES
    ('A', 20), ('A', 40), ('B', 25), ('B', 25), ('C', 10), ('C', 10);
    
    SELECT [User], [Total], SUM([Total]) OVER(PARTITION BY [User] ORDER BY [User]) AS RunningTotal
    FROM @T;
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.