๐ง SQL Interview Question (Moderate & Revenue Analysis)
๐
orders(order_id, customer_id, order_amount)
โ Ques :
๐ Find customers who contribute more than 30% of the total company revenue.
๐งฉ How Interviewers Expect You to Think
โข Calculate overall total revenue
โข Aggregate revenue at customer level
โข Compare individual contribution against total
โข Avoid recalculating total multiple times inefficiently
๐ก SQL Solution
WITH total_revenue AS (
SELECT SUM(order_amount) AS total_rev
FROM orders
),
customer_revenue AS (
SELECT
customer_id,
SUM(order_amount) AS cust_rev
FROM orders
GROUP BY customer_id
)
SELECT c.customer_id
FROM customer_revenue c
CROSS JOIN total_revenue t
WHERE c.cust_rev > 0.30 * t.total_rev;
๐ฅ Why This Question Is Powerful
โข Tests percentage-based business logic
โข Evaluates ability to combine multiple aggregations
โข Reflects real-world Pareto (80/20) analysis scenarios
โข Common in product, growth & revenue analytics interviews
โค๏ธ React if you want more real interview-level SQL questions
Post #2083
1.34K
- โค 1