Chewy's merchandising team needs a category-level view of revenue from the most recently completed quarter. Assume the reporting date is 2025-04-15, so the last quarter is Q4 2024, from 2024-10-01 through 2024-12-31.
Write a PostgreSQL query that calculates revenue by product category.
Requirements
- Include only orders with
status = 'completed' placed during Q4 2024.
- Calculate revenue as
quantity * unit_price from order items.
- Group results by product category, labeling a missing category as
Uncategorized.
- Sort categories by total revenue descending, then category name ascending to break ties.