1 reply
say date based.
Then before the insert
Select Max(transaction_date) from transactions
Select running)total from transactions where transaction_date = [From above]
insert into transactions ..... , from_above
If the values you are adding consist of +ve & -ve values you could try
insert into transactions select (......,(select sum(values) from transactions)
Aggregates tend to get quite expensize on big tables though.
You could also do a pseudo trigger.
Have a table called running-total with one field in it called surprise running-total.
Add your new value to it and then insert that into the main table.
Obviously in the latter case you'd want to make sure the two tables were kept in step.
Given running total is derived data are you sure you want to store it, instead of just calculating it for output when you need it.
This discussion is closed to new replies.
Trending Software posts
Sort by Trending