How do you optimize query performance on a database containing billions of rows of historical data?
Use the provided PostgreSQL schema to produce an efficient report for completed events during 2025. The result should aggregate monthly activity for active accounts and calculate each account and event type's change from the previous month.
Output
- One row per active account, event type, and month with qualifying activity.
- Columns:
account_name, region, event_name, month_start, event_count, total_amount, prior_month_amount, and amount_change.
- Sort by account, event type, and month in ascending order.