Cumulative sum in SQL Server
CREATE TABLE [dbo].[TempTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Value] [float] NULL
) ON [PRIMARY]
GO
select t1.ID, t1.Value, SUM(t2.Value) as Total
from TempTable t1
inner join TempTable t2 on t1.ID >= t2.ID
group by t1.ID, t1.Value
order by t1.ID
No comments:
Post a Comment
Thanks for comments.