Your question is SQL Top 10 Sales Query. 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.
Checkr's product analytics team wants to identify the products generating the most sales. Write a PostgreSQL query that returns the top 10 products by completed sales during the previous calendar quarter. For the sample data, assume the reporting date is 2025-01-15, so the previous quarter is October 1 through December 31, 2024.
orders, order_items, and products.status = 'completed' from the previous calendar quarter. Use an inclusive start date and exclusive end date.quantity * unit_price, aggregated by product.The data includes completed, cancelled, out-of-quarter, and null-status orders. Product Background Check API has no sales in the previous quarter, and product Identity Verification ranks eleventh.
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Checkr product name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order processing status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-line identifier |
| order_id | INT | Related order identifier |
| product_id | INT | Related product identifier |
| quantity | INT | Number of units purchased |
| unit_price | NUMERIC(10,2) | Price charged per unit |