How would you optimize a slow-performing SQL query that aggregates large volumes of daily diagnostic data?