Task
ShopSwift wants to identify which product categories are driving shipping cost increases. Write a SQL query to find the top categories contributing to shipping cost growth from February 2024 to March 2024.
Requirements
- Use only the
shipments table.
- For each
category, calculate total shipping cost in February 2024 and March 2024.
- Return only categories where March shipping cost is greater than February shipping cost.
- Output the category, February total, March total, and the growth amount (
march_total - february_total).
- Sort by growth amount in descending order and return the top 3 categories.
Table Definition
shipments
| Column | Type | Description |
|---|
| shipment_id | INT | Unique shipment record ID |
| category | VARCHAR(50) | Product category |
| shipped_date | DATE | Shipment date |
| shipping_cost | DECIMAL(10,2) | Cost charged for shipping |
| carrier | VARCHAR(50) | Shipping carrier |
Sample Data
| shipment_id | category | shipped_date | shipping_cost | carrier |
|---|
| 1 | Electronics | 2024-03-05 | 120.00 | FedEx |
| 2 | Books | 2024-02-10 | 25.00 | UPS |
| 3 | Electronics | 2024-02-12 | 80.00 | DHL |
| 4 | Home | 2024-03-08 | 60.00 | UPS |
| 5 | Books | 2024-03-14 | 40.00 | FedEx |
| 6 | Toys | 2024-02-20 | 30.00 | USPS |
| 7 | Home | 2024-02-18 | 55.00 | DHL |
| 8 | Electronics | 2024-03-18 | 90.00 | UPS |
| 9 | Toys | 2024-03-21 | 70.00 | FedEx |
| 10 | Beauty | 2024-03-25 | 20.00 | USPS |
Expected Output
| category | february_total | march_total | growth_amount |
|---|
| Electronics | 80.00 | 210.00 | 130.00 |
| Toys | 30.00 | 100.00 | 70.00 |
| Books | 25.00 | 80.00 | 55.00 |