Find product pairs that appear together in at least 2 different orders. A SKU listed twice in the same order counts once, and NULL SKUs are ignored. Return `sku_a`, `sku_b` (alphabetically sku_a < sku_b), `orders_together`, and `pct_of_orders` = ROUND(100.0 * orders_together / total orders, 1), where total orders = number of distinct orders containing at least one non-NULL SKU. Order by `orders_together` DESC, then `sku_a`, `sku_b`.
| Column | Type |
|---|---|
| order_id | INTEGER |
| sku | TEXT |
| order_id | sku |
|---|---|
| 1 | MILK |
| 1 | BREAD |
| 1 | EGGS |
| 2 | MILK |
| 2 | BREAD |
| 3 | MILK |
| 3 | EGGS |
| 4 | BREAD |
| sku_a | sku_b | orders_together | pct_of_orders |
|---|---|---|---|
| BREAD | MILK | 3 | 60 |
| EGGS | MILK | 2 | 40 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Top-3 Products per Category with Ties · Driver Longest Active-Day Streak ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.