DataLane

2. Top products by units sold

mediumProNot started~10 minJoinsAggregation

Asked in screens shaped like: Amazon, Walmart, Instacart

Merchandising wants units sold per product. The quantity lives on the line items, not the order header — summing orders.amount here is the classic wrong answer because an order can carry several products.

Requirements

  • Columns: product_id, name, units
  • units is SUM(qty) from order_items
  • Order by units descending, then product_id ascending

Expected output

product_id, name, units

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close