-4

Every record amount sum into Total column

  id            Amount           total
  --------------------------------------------
  1              100            100              
  1              50             150         
  1              60             210        
  1              10             220      
  2              70             290
  2              10             300

Any suggestion would be very much appreciated.

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
kari kalan
  • 497
  • 3
  • 20

1 Answers1

1

You want window function :

select t.*, 
       sum(amount) over (order by id rows between unbounded preceding and current row) as total
from table t;
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52