By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| personID | DocDate | DocID | Fee | ISDeb |
|---|---|---|---|---|
| 88 | 2/16 | 3 | 3 | 0 |
| 88 | 2/17 | 4 | 7 | 0 |
| personID | DocDate | DocID | Fee | IsDebit |
|---|---|---|---|---|
| 88 | 2/14 | 1 | 5 | 1 |
| 88 | 2/15 | 2 | 5 | 1 |
| personID | deb_DocID | deb_Fee | Cre_DocID | Cre_Fee | remain_Cre_Fee |
|---|---|---|---|---|---|
| 88 | 1 | 5 | 3 | 3 | 0 |
| 88 | 1 | 5 | 4 | 7 | 5 |
| 88 | 2 | 5 | 4 | 7 | 0 |
| personid | docdate | docid | fee | isdebit |
|---|---|---|---|---|
| 88 | 2021-02-14 | 1 | 5 | True |
| 88 | 2021-02-15 | 2 | 5 | True |
| personid | docdate | docid | fee | isdebit |
|---|---|---|---|---|
| 88 | 2021-02-16 | 3 | 3 | False |
| 88 | 2021-02-17 | 4 | 7 | False |
| personid | docid | fee | debit_sum |
|---|---|---|---|
| 88 | 1 | 5 | 5 |
| 88 | 2 | 5 | 10 |
| personid | docid | fee | credit_sum |
|---|---|---|---|
| 88 | 3 | 3 | 3 |
| 88 | 4 | 7 | 10 |
| personid | deb_docid | deb_fee | cre_docid | cre_fee | cre_fee_remaining |
|---|---|---|---|---|---|
| 88 | 1 | 5 | 3 | 3 | 0 |
| 88 | 1 | 5 | 4 | 7 | 5 |
| 88 | 2 | 5 | 4 | 7 | 0 |