I have a table structure
| accountID | amount | total | seq |
|---|---|---|---|
| a1 | 1 | 10 | 0 |
| a1 | -10 | 11 | 1 |
| a1 | 2 | 1 | 2 |
| a2 | 20 | 1 | 0 |
| a2 | 1 | 1 | 1 |
The total of the first record is not necessary to be 0
If its not the first record, the current total should be calculated by previous_record.amount + previous_record.total
In the example above, I want to select the last record because the total is wrong. It supposes equal to 21 (1+20).
I have coded a program that retrieve all data and do the verification. But the data size is too big (~1M records). It takes really long time. So I seek a solution that use SQL.
