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
idnamecategorypricecost
1KeyboardAccessories25001500
2MouseAccessories1200700
3HeadphonesAudio35002000
4MonitorDisplays120009000
5LaptopComputers6000048000
… 5 more rows
inventory
product_idstock
140
225
360
415
520
… 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.”
SQL editor Ctrl+Enter to run
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.

Case closed.

Ready for the next one?

Next: Case 034 — At-Risk Stock →