Intermediate
Case 33 of 50
Case 033: Profit Margin
productsinventory
The manager finally shares something Alex hasn't seen before: product cost, not just price.
"Price tells you revenue. Could you get me margin instead — what we actually keep? And I'd love to know how much profit is sitting in the warehouse right now, at current stock levels."
The data Alex is looking at
products
| id | name | category | price | cost |
|---|---|---|---|---|
| 1 | Keyboard | Accessories | 2500 | 1500 |
| 2 | Mouse | Accessories | 1200 | 700 |
| 3 | Headphones | Audio | 3500 | 2000 |
| 4 | Monitor | Displays | 12000 | 9000 |
| 5 | Laptop | Computers | 60000 | 48000 |
| … 5 more rows | ||||
inventory
| product_id | stock |
|---|---|
| 1 | 40 |
| 2 | 25 |
| 3 | 60 |
| 4 | 15 |
| 5 | 20 |
| … 5 more rows | |
TASK
Help Alex answer the manager:
“Show each product's price, cost, profit margin as a percentage of its price, and the total potential profit if all current stock sold out — highest margin first.”
Write a query above and hit Run to see what comes back.
No hints requested yet — click "Get a hint" when you're stuck.
Alex's final query — this is for reference. Copy it into your own thinking, not into the editor above.
SELECT
products.name,
products.price,
products.cost,
ROUND((products.price - products.cost) * 100.0 / products.price, 1) AS margin_pct,
(products.price - products.cost) * inventory.stock AS potential_profit
FROM products
JOIN inventory ON inventory.product_id = products.id
ORDER BY margin_pct DESC;
What that query returns
Case Debrief
Calculated columns, ROUND
- Business ratios like margin are just arithmetic on existing columns — the skill is knowing which columns to combine, not new SQL syntax.