Write a query using SQL window functions to calculate rolling three-month moving averages of client transactions.
Use the clients and transactions tables. Calculate monthly transaction totals for each client, then calculate the average of the current month and available transaction totals from the preceding two calendar months.
client_id, client_name, month_start, monthly_transaction_total, and rolling_three_month_avgclient_id, then month_start ascending| Column | Type | Description |
|---|---|---|
| client_idPK | INT | Unique client identifier |
| client_name | VARCHAR(150) | Client display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| client_id | INT | References clients.client_id |
| transaction_date | DATE | Date the transaction occurred |
| amount | DECIMAL(12,2) | Transaction amount |