In order to make this work, I have to assume that you have a column in BUF_TRANSACTIONS that can be grouped on, (i.e. CUSTOMER_ID). You cannot create a calculated column that uses data from multiple rows without using grouping.
I created a simple BUFTRANSACTIONS table as follows:
Then you can create a calculated column that uses sub-queries to sum the values of each TRAN_CODE and perform the equation you want.
SELECT BUF_TRANS.ID,
(SELECT SUM(A.TRAN_AMOUNT) FROM BUF_TRANSACTIONS A WHERE A.ID = BUF_TRANS.ID AND A.TRAN_CODE = ‘DP’) +
(SELECT SUM(A.TRAN_AMOUNT) FROM BUF_TRANSACTIONS A WHERE A.ID = BUF_TRANS.ID AND A.TRAN_CODE = ‘IE’) -
(SELECT SUM(A.TRAN_AMOUNT) FROM BUF_TRANSACTIONS A WHERE A.ID = BUF_TRANS.ID AND A.TRAN_CODE = ‘WD’) AS CALC
FROM BUF_TRANSACTIONS BUF_TRANS
GROUP BY BUF_TRANS.ID
ORDER BY BUF_TRANS.ID ASC
If you need a finer granularity in your calculation, you can add a group by on a transaction date or whatever other column makes sense.