Can you write an efficient SQL query to aggregate rolling windows of customer transaction data?
Assume the required window is 30 calendar days and only posted transactions should be included. Aggregate transactions by customer and transaction date before calculating the rolling total.
customer_id, customer_name, transaction_date, daily_amount, and rolling_30_day_amountcustomer_id, then transaction_date ascending| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| segment | VARCHAR(30) | Customer segment |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| customer_id | INT | Customer associated with the transaction |
| transaction_date | DATE | Calendar date of the transaction |
| amount | NUMERIC(12,2) | Transaction amount |
| status | VARCHAR(20) | Transaction processing status |