Optimize a slow-running query that aggregates millions of historical home price records at Redfin.
Using the provided schema, return monthly statistics for valid single-family home price records from 2024. The query should avoid unnecessary processing and include the previous available monthly average for each market.
Output
- One row per market and month, with
market_name, month_start, average_price, record_count, previous_month_average, and percent_change
- Include only valid records from 2024 and markets with matching properties
- Sort by
market_name, then month_start ascending