Business Context
Henry Schein wants a regional view of product demand to support inventory planning across its distribution network. Use completed sales orders from the last completed quarter, defined here as Q4 2025.
Task
Write a PostgreSQL query that returns the top three products by total units sold within each region from October 1 through December 31, 2025.
Requirements
- Include only orders with
status = 'completed' and order dates within Q4 2025, including both boundary dates.
- Join orders to regions, order items, and products.
- Aggregate total units by region and product, treating a NULL quantity as zero.
- Rank products independently within each region using a window function.
- Return products with ranks 1 through 3, ordered by region, rank, and product name.