Calculate row value based on previous and actual row values
13
votes
5
answers
78370
views
Hi everyone and thanks for your help.
I have the following situation: a table called statements that contains fields **id**(int), **stmnt_date**(date), **debit**(double), **credit**(double) and **balance**(double)
I want to calculate the balance following these rules:
The first row balance (**chronologically**) = debit - credit and for the rest of the rows
**current row balance = chronologically previous row balance + current row debit - current row credit** As you can see on the picture above the rows are not arranged by date and that's why I used the word chronologically twice to emphasize on the importance of the stmnt_date value. Thank you very much for your help.
I have the following situation: a table called statements that contains fields **id**(int), **stmnt_date**(date), **debit**(double), **credit**(double) and **balance**(double)

The first row balance (**chronologically**) = debit - credit and for the rest of the rows
**current row balance = chronologically previous row balance + current row debit - current row credit** As you can see on the picture above the rows are not arranged by date and that's why I used the word chronologically twice to emphasize on the importance of the stmnt_date value. Thank you very much for your help.
Asked by Mohamed Anis Dahmani
(243 rep)
Mar 6, 2015, 12:43 AM
Last activity: Sep 8, 2022, 07:30 AM
Last activity: Sep 8, 2022, 07:30 AM