Your question is SQL Top Products by Region. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Roche's commercial analytics team needs a regional view of product performance. Assume the reporting date is 2025-07-15, so the last completed quarter is 2025-04-01 through 2025-06-30.
Write a PostgreSQL query to identify the top three Roche products by revenue in each region.
quantity * unit_price and aggregate it by region and product.RANK(), retaining ties at the third rank.| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sales record identifier |
| product_id | INT | References products.product_id |
| region_id | INT | References regions.region_id |
| sale_date | DATE | Date on which the sale was recorded |
| quantity | INT | Number of units sold |
| unit_price | DECIMAL(12,2) | Revenue per unit in reporting currency |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique Roche product identifier |
| product_name | VARCHAR(100) | Roche product name |
| Column | Type | Description |
|---|---|---|
| region_idPK | INT | Unique commercial region identifier |
| region_name | VARCHAR(100) | Commercial region name |