From 36f8c2315fc9083a4953499de8800c0e68cad777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20=22flowdy=22=20He=C3=9F?= Date: Sun, 5 Jun 2016 16:18:49 +0200 Subject: [PATCH] added view "ReconstructedBankStatement" to compare with the actual statement from the club's bank --- schema.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 +;