0

I want to get the balance via T-SQL from this table

TID amount  balance
--- -----   -------
1    100   100
2    50    150
3    30    180
4    300   480
5    200   680

Can anyone please support me on this case?

Best regards.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425

1 Answers1

1

One way is using window function sum:

select
    t.*,
    sum(amount) over (order by tid) balance
from your_table t;
Gurwinder Singh
  • 37,207
  • 6
  • 50
  • 70