Your question is Rolling 30-Day Transaction Average. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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 |