Scotiabank's customer analytics team wants to monitor recent transaction behaviour. Write a PostgreSQL query that calculates a rolling 30-day average transaction amount for each active customer.
Use the current transaction date plus the preceding 29 calendar days, and calculate the average across non-null transactions in that window.
transactions to customers and include only active customers.| Column | Type | Description |
|---|---|---|
| customer_idPK | INTEGER | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer's name |
| is_active | BOOLEAN | Whether the customer is currently active |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique transaction identifier |
| customer_id | INTEGER | Customer associated with the transaction |
| transaction_date | DATE | Date the transaction occurred |
| amount | NUMERIC(12,2) | Transaction amount |