Apex Systems wants a quarterly view of product performance in its sales analytics reporting. Write a PostgreSQL query that identifies the highest-grossing products in each sales region for the last completed quarter, defined here as April 1, 2025 through June 30, 2025.
Requirements
- Join
regions, orders, order_items, and products to calculate product revenue by region.
- Include only orders whose
order_date falls within the specified quarter.
- Calculate gross revenue as
quantity * unit_price and aggregate it by region and product.
- Use a window function to return all products whose rank is within the top three positions per region. Products tied at a qualifying rank must all be included.
- Return
region_name, product_name, gross_revenue, and the ranking value, ordered by region and revenue descending.