Amazon-style Company ChallengeHardVerified answerSQLite live

Seller Revenue and Performance Dashboard

For each seller with at least 2 order line items fulfilled, show their total items sold, total revenue, average product rating, and revenue rank among all sellers.

  • Window functions
  • Joins
  • Subqueries
  • Aggregation
  • Numeric functions

Challenge brief

Understand the request

Marketplace Analytics is preparing the quarterly seller review and needs a ranked performance report combining sales, revenue, and customer satisfaction.

Build a ranked seller performance report combining revenue, items sold, and average rating.

Return

  • seller_name
  • items_sold (total distinct order line items)
  • total_revenue (price x quantity, rounded to 2 decimals)
  • avg_rating (rounded to 2 decimals)
  • revenue_rank (RANK by total revenue desc)

Constraints

  • Only include sellers associated with at least two fulfilled order line items
  • Revenue must be calculated once per order line and must not be multiplied by reviews
  • Average rating uses all available product reviews without excluding unrated sellers
  • Equal revenue totals share a rank; return highest revenue first

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

sellers

  • seller_idINTEGER
  • seller_nameVARCHAR(100)

products

  • product_idINTEGER
  • seller_idINTEGER

order_items

  • order_item_idINTEGER
  • product_idINTEGER
  • quantityINTEGER
  • priceREAL

reviews

  • product_idINTEGER
  • ratingINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Sales and reviews are separate one-to-many facts. Aggregate each path to seller grain before joining them, or reviews will multiply order-line revenue.

Hint 2

Build one CTE for seller_sales and another for seller_ratings. Join both summaries to sellers, filter on items_sold, and rank the already-safe revenue totals.

Hint 3

Scaffold: WITH seller_sales AS (... GROUP BY seller_id), seller_ratings AS (... GROUP BY seller_id) SELECT the seller metrics, then rank the pre-aggregated revenue totals.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
WITH seller_sales AS (SELECT p.seller_id, COUNT(oi.order_item_id) AS items_sold, SUM(oi.price * oi.quantity) AS total_revenue FROM products p INNER JOIN order_items oi ON p.product_id = oi.product_id GROUP BY p.seller_id), seller_ratings AS (SELECT p.seller_id, AVG(r.rating) AS avg_rating FROM products p INNER JOIN reviews r ON p.product_id = r.product_id GROUP BY p.seller_id) SELECT s.seller_name, ss.items_sold, ROUND(ss.total_revenue, 2) AS total_revenue, ROUND(sr.avg_rating, 2) AS avg_rating, RANK() OVER (ORDER BY ss.total_revenue DESC) AS revenue_rank FROM sellers s INNER JOIN seller_sales ss ON s.seller_id = ss.seller_id LEFT JOIN seller_ratings sr ON s.seller_id = sr.seller_id WHERE ss.items_sold >= 2 ORDER BY total_revenue DESC;

Why this works

Sales and ratings are aggregated independently before they are joined to sellers. That preserves the order-item grain and prevents multiple reviews from multiplying revenue. RANK then orders the eligible seller totals; BookWorld has no fulfilled line items and does not qualify.

Success check

3 sellers — HomeEssentials (29.92 rank 1), TechGear Pro (98.88 rank 2), GlobalElectronics (1.98 rank 3)

Expected result

Use this output to verify values, aliases, ordering, and row count.

seller_nameitems_soldtotal_revenueavg_ratingrevenue_rank
TechGear Pro5308.9151
HomeEssentials5269.9442
GlobalElectronics291.9843

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.