Your question is Top Brands by State. 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.
Chewy wants a state-level view of which pet food brands are selling the most. Write a PostgreSQL query using joins, aggregation, date filtering, and a window function.
Use 2026-08-29 as the reporting date for the sample data. Include orders from the last 30 days, exclude non-pet-food products, and rank brands by total units sold.
orders, order_items, and products.| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| state | VARCHAR(2) | Shipping state abbreviation |
| order_date | DATE | Date the order was placed |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique line-item identifier |
| order_id | INT | References orders.order_id |
| product_id | INT | References products.product_id |
| quantity | INT | Number of units in the line item |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| brand | VARCHAR(100) | Product brand |
| category | VARCHAR(50) | Product category |