How do you optimize SQL queries for performance?
Demonstrate your approach with a PostgreSQL query over the supplied tables. Return monthly revenue by product category for completed orders, including the previous available month, percentage change, and a three-month rolling revenue total.
Output
- One row per category and revenue month, with
month, category, monthly_revenue, previous_month_revenue, revenue_change_percent, and rolling_three_month_revenue.
- Include only completed orders from January through April 2025. Sort by
category, then month.