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
  • 732,580
  • 175
  • 1,330
  • 1,459

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
  • 38,557
  • 6
  • 51
  • 76