How do you optimize a slow-running SQL query that aggregates transaction data across millions of rows?