I have two tables, first call it "transactions"
transaction_id | transaction_type | amount |
---|---|---|
101 | 1 | 50.00 |
102 | 2 | 25.00 |
103 | 3 | 35.00 |
104 | 2 | 15.00 |
105 | 1 | 60.00 |
and second call it "transaction_types"
id | description |
---|---|
1 | Deposit |
2 | Retirement |
3 | Inner_transaction |
The "id" column in the "transaction_types" table, corresponds with the "transsaction_id" in the first table
Suppose that the initial balance is $100,000.00. I should write a query to get the historical account balance. The table that I should show is this:
transaction_id | initial_balance | deposit | withdrawal | final_balance |
---|---|---|---|---|
101 | 100000 | 50.00 | 100050 | |
102 | 100050 | 25.00 | 100025 | |
103 | 100025 | 100025 | ||
... | ... | ... | ... | ... |
I write this code in SAS using a PROC SQL:
TITLE "Balance Historico de la Wallet Empresarial";
PROC SQL;
SELECT transaction_id,
100000 AS initial_balance FORMAT=DOLLAR32.2,
"" AS deposit,
"" AS withdrawal,
"" AS final_balance
FROM _LIB.TRANSACTIONS;
QUIT;
But I don't know how fill the other columns.