Write a query to calculate a running total or a moving average using window functions.
Use the provided account and transaction data. Calculate both metrics for each transaction, ordered chronologically within each account. Include transactions with no associated account.
account_id, account_name, transaction_date, amount, running_total, and moving_averageaccount_id ascending with NULL account IDs last, then transaction_date and transaction_id ascending| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| account_name | VARCHAR(100) | Account display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Associated account identifier |
| transaction_date | DATE | Transaction posting date |
| amount | NUMERIC(10,2) | Transaction amount |