Subject | How to create an calculated field for bank balance? |
---|---|
Author | K Z |
Post date | 2012-09-12T18:28:32Z |
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]
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]