Practice · medium · dataset: ecom
Product pairs bought together
Find pairs of distinct products that appear in the same order, and count how many orders contain both.
Return product_a, product_b, and order_count, with product_a less than product_b so each
pair appears once. Sort by order_count descending, then by product_a ascending, then by
product_b ascending, and keep the top 10 pairs.
Tables available
| Table | Columns |
|---|---|
order_items |
order_id, product_id, quantity, unit_price |
Each order has at most one row per product. A pair is unordered: (9, 24) and (24, 9) are the same
pair and must not both appear.
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.