Given a dataset, how would you optimize a slow-running query or pipeline?
Use the provided dataset to demonstrate an optimized PostgreSQL query that calculates completed event activity for active accounts during January 2025. The query should avoid unnecessary rows and preserve accounts whose qualifying events have no item value.
Output
- Return at most five rows with
account_id, account_name, event_count, and total_value.
- Include only active accounts with completed January events.
- Order by
total_value descending, then account_id ascending.