Skip to main content
All Problems
hard0% acceptance

Product Profit Margin Ranking

Rank products by their profit margin. Use a CTE to compute margin as (price - cost) / price * 100 for each product. Then show product name, price, cost, margin (rounded to 2 decimals), and the rank (highest margin = 1). Only include products where cost is not NULL. Sort by rank.

Schema

🔑idINT
nameTEXT
🔗category_idINT
priceREAL
costREAL
stock_quantityINT
created_atTIMESTAMP
postgresql

Run your query to see results

Press Ctrl + Enter to execute