IntermediateBasic SELECT

Show products with profit margin percentage

The query

SQL
SELECT
  name,
  price,
  cost,
  ROUND((price - cost) / price * 100, 2) AS margin_pct
FROM products
WHERE cost IS NOT NULL AND cost > 0
ORDER BY margin_pct DESC;
Tested against PostgreSQL 16

Note

Calculated columns make reports self-contained without application-layer math.

Tables referenced