0

hi guys i need help!

i've a table sql like this:

id | in | out
1  | 32 | 23
2  | 4  | 0
3  | 10 | 3

i need a result like this:

id | in | out| cumulative
1  | 32 | 23 | 9
2  | 4  | 0  | 13
3  | 10 | 3  | 20

is possible to do in sql ?? how? thanks

komm
  • 71
  • 6

1 Answers1

1

Could use a subquery like this:

select id,
      [in],
      [out],
      (SELECT ABS(SUM([out] - [in])) 
        from ##temp as c2 where id <= c1.id) as cumulative
from ##temp as c1

Where ##temp is your table

Charly
  • 101
  • 1
  • 8
Craig Foster
  • 109
  • 1
  • 7