Revenue by category with multi-join
SQL
Hard
2 views
Problem Description
Orders, OrderItems, Products. Show category-wise revenue for shipped orders only.
Sample Test Case
Input:
Orders(status), OrderItems(qty, price), Products(category)
Constraints
Assume revenue = qty*price
Official Solution
SELECT p.category, SUM(oi.qty * oi.price) AS revenue FROM Orders o JOIN OrderItems oi ON oi.order_id = o.order_id JOIN Products p ON p.product_id = oi.product_id WHERE o.status = 'SHIPPED' GROUP BY p.category ORDER BY revenue DESC;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!