June 21, 2012 at 6:36 am
hi all
how to calculate Total value below example
ID NameValueTotal Value
1x2020
2y1030
3z3060
4a50110
5b40150
6c80230
i want to add total value like fibonacci series
first row- [Total Value] column display value of id=1
2 row - [Total Value] column display value of ID 1,2
3 row - [Total Value] column display value of ID 1,2,3
.............etc
Prasad.N
Hyderabad-India.
June 21, 2012 at 6:42 am
Sounds like a running totals solution
June 21, 2012 at 8:15 am
hi all,
i got answers
declare @table table (rid int, tot int)
insert into @table
select 1,10
union
select 2,20
union
select 3,30
union
select 4,40
union
select 5,50
union
select 6,70
SELECT rid,tot,
(SELECT SUM(tot)
FROM @table F1
WHERE F1.rid <= F2.rid and rid>2) AS b
FROM @table F2 --where PdaId=38
where rid>2
Prasad.N
Hyderabad-India.
June 21, 2012 at 8:20 am
That is bad one. Triangular-joins are performance killers in this case.
My advice is to read the article pointed in the first reply.
June 21, 2012 at 11:13 am
Hi Prasad,
Please try this SELECT statement below:
select t.ID,t.name,t.value,(select sum(s.value) from T1 s where s.id<=t.id)
from T1 t
Regards,
Ravi.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply