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
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Guoxiong 8,216 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.