Write a query to identify top-performing products based on specific time-window criteria at Wayfair.
Use completed orders from the current 30-day window, 2025-01-01 through 2025-01-30, and compare them with the preceding 30-day window, 2024-12-02 through 2024-12-31. Return the three products with the highest current-window revenue.
Output
- One row per qualifying product with
product_id, product_name, current_revenue, previous_revenue, and revenue_change_percent
- Include products with no previous-window revenue, representing the percentage as NULL
- Sort by
current_revenue descending, then product_id ascending
Output details
- Treat both date-window endpoints as inclusive.
- Return
current_revenue and previous_revenue as 0 when no completed orders exist in the respective window.
- Round
revenue_change_percent to two decimal places.
- Set
revenue_change_percent to NULL whenever previous_revenue equals 0.
- Consider every product, including products with no completed orders in either window, before selecting the top three.