Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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;