added view "ReconstructedBankStatement" to compare with the actual statement from the club's bank

This commit is contained in:
Florian "flowdy" Heß 2016-06-05 16:18:49 +02:00
parent f2f1bdf036
commit 36f8c2315f
1 changed files with 20 additions and 0 deletions

View File

@ -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
;