🧠 SQL Interview Question (Category Contribution % - Tricky)
📌
sales(category, product_id, revenue)
❓ Ques :
👉 For each category, calculate percentage contribution of each product’s revenue within that category
👉 Return category, product_id, revenue, contribution_percentage
🧩 How Interviewers Expect You to Think
• Calculate total revenue per category 📊
• Divide product revenue by category total
• Use window functions (SUM OVER)
💡 SQL Solution
SELECT
category,
product_id,
revenue,
(revenue * 100.0) / SUM(revenue) OVER (
PARTITION BY category
) AS contribution_percentage
FROM sales;
🔥 Why This Question Is Powerful
• Tests real business KPI calculation skills 🧠
• Evaluates understanding of window functions with aggregation
• Very common in Amazon, Flipkart, analytics roles
❤️ React if you want more real interview-level SQL questions 🚀
Post #2132
7.52K
- ❤ 14
- 🔥 1