Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,


i have one table and there is record like that


ID Amount
1 100
2 500
3 1500
4 5800

now i want to get record like
1 100 100
2 500 600
3 1500 2100
4 5800 7900


can any one help me for this query to get record like this...!!

Thank You all...!!
Posted
Comments
Zoltán Zörgő 3-Oct-12 5:30am    
You want a running summary?
Yatin chauhan 3-Oct-12 6:21am    
Yes Zoltan....!!

 
Share this answer
 
Comments
Yatin chauhan 3-Oct-12 6:04am    
Thank a Lot Dylan Morley....!!!!
SQL
insert into @t
select 1,10
union
select 2,12
union
select 3,3
union
select 4,15
union
select 5,23


select * from @t

select t1.id, t1.SomeNumt, SUM(t2.SomeNumt) as sum
from @t t1
inner join @t t2 on t1.id >= t2.id
group by t1.id, t1.SomeNumt
order by t1.id



Thanks
 
Share this answer
 
If you need running totals in just T-SQL, start from here: http://www.sqlhacks.com/Summary/Running_Total[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900