Subtracting a value from first row and the result to be subtracted further from the next row

Could someone please help to answer the issue posted at

php - Subtracting a value from first row and the result to be subtracted further from the next row - Stack Overflow ?

Your ealiest reply is highly appreciated. Thank you.

Wheres your original query?

And please dont ask us to post in a different forum. Answers should be posted HERE, so other members and future members can benefit from the time/energy and answer.

As stated in that four year old post, programming help forums are not free code writing services. If you happen to have this same assignment, you will need to make an attempt at solving it yourself.

BTW - you would NOT UPDATE (subtract) an amount from a column in a database table as this doesn’t provide an audit trail. You would instead INSERT a row in a table (could be separate table for the points used) for every transaction that affects the value. For something like a points system, where you would use the oldest points first, you would insert row(s) against the original points, referencing the id of the original row, until you have accounted for the total number of points used. For the example given, there would be two rows inserted, first with a -450 amount, with a reference to id 1, then a row with a -150 amount, with a reference to id 2.

Note: the original table design posted would have an account number column, so that the table will support multiple accounts and a datetime column, so that you will know when each transaction occurred.

Sponsor our Newsletter | Privacy Policy | Terms of Service