diff --git a/schema.sql b/schema.sql index 231add6..5e43635 100644 --- a/schema.sql +++ b/schema.sql @@ -238,3 +238,23 @@ CREATE VIEW Balance AS ) AS pr ON Account.ID=pr.ID ; +CREATE VIEW ReconstructedBankStatement AS + SELECT c.date AS date, + c.purpose AS purpose, + account, + c.value AS credit, + NULL AS debit + FROM Credit AS c + LEFT OUTER JOIN Debit AS d ON c.ID=d.targetCredit + GROUP BY c.ID + HAVING count(d.billId) == 0 -- exclude internal transfers + UNION + SELECT date, + purpose, + debtor AS account, + NULL AS credit, + value AS debit + FROM Debit + WHERE targetCredit IS NULL -- exclude internal transfers + ORDER BY date ASC +;