Subject | Re: [firebird-support] How to create an calculated field for bank balance? |
---|---|
Author | Ismael L. Donis Garcia |
Post date | 2012-09-12T19:40:19Z |
Because order by desc?.
This would revert the order of the operations.
=========
|| ISMAEL ||
=========
This would revert the order of the operations.
=========
|| ISMAEL ||
=========
----- Original Message -----
From: K Z
To: firebird-support@yahoogroups.com
Sent: Wednesday, September 12, 2012 2:28 PM
Subject: [firebird-support] How to create an calculated field for bank balance?
Hello,
Is there a trick to have this?
CREATE TABLE BANK_ACCOUNT
(
ID INTEGER NOT NULL,
OCCURRENCE TIMESTAMP,
DESCRIPTION VARCHAR(100),
AMOUNT DECIMAL(10,2) NOT NULL
CONSTRAINT PK_
BANK_ACCOUNT _1 PRIMARY KEY (ID)
);
CREATE VIEW BANK_ACCOUNT_STATEMENT (ID,
OCCURRENCE ,
DESCRIPTION , AMOUNT, BALANCE)
AS
SELECT r.*, (Calculated Field)
as BALANCE
FROM
BANK_ACCOUNT r
order by r.OCCURRENCE
desc
;
Calculated Field is the previous record balance plus the current record field AMOUNT. If there is no previous record, then is the current record field AMOUNT.
For example:
ID DESCRIPTION AMOUNT BALANCE
1 Deposit 10 10
2 Check -5 5
3 Check -10 -5
4 Credit transfer 50 45
Thank you in advance for your support.
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]