Business context
Natural Intelligence uses product-level revenue reporting to evaluate performance across its comparison and betting surfaces. Assume the report is run on 2025-01-15, so the last completed quarter is Q4 2024.
Task
Write a PostgreSQL query that returns the top five products by completed revenue during the last completed calendar quarter.
Requirements
- Join products to their categories and transactions.
- Include only transactions with
status = 'completed' within the quarter ending before the reporting date.
- Aggregate revenue by product, order from highest to lowest revenue, and use
product_id as a deterministic tie-breaker.