2017-01-19 21:44:22 +01:00
|
|
|
DROP VIEW IF EXISTS ReconstructedBankStatement;
|
|
|
|
CREATE VIEW ReconstructedBankStatement AS
|
|
|
|
SELECT c.date AS date,
|
|
|
|
c.purpose AS purpose,
|
2017-01-29 15:57:34 +01:00
|
|
|
c.category AS category,
|
2017-01-19 21:44:22 +01:00
|
|
|
account,
|
|
|
|
c.value AS credit,
|
|
|
|
NULL AS debit
|
|
|
|
FROM Credit AS c
|
|
|
|
LEFT OUTER JOIN Debit AS d ON c.credId = d.targetCredit
|
|
|
|
GROUP BY c.credId
|
|
|
|
HAVING count(d.billId) == 0 -- exclude internal transfers
|
|
|
|
UNION
|
|
|
|
SELECT date,
|
|
|
|
purpose,
|
2017-01-29 15:57:34 +01:00
|
|
|
category AS category,
|
2017-01-19 21:44:22 +01:00
|
|
|
debtor AS account,
|
|
|
|
NULL AS credit,
|
|
|
|
value AS debit
|
|
|
|
FROM Debit
|
|
|
|
WHERE targetCredit IS NULL -- exclude internal transfers
|
|
|
|
ORDER BY date ASC
|
|
|
|
;
|