Paired Products
Start Timer
0:00:00
Let’s say we have two tables, transactions and products. Hypothetically the transactions table consists of over a billion rows of purchases bought by users.
We are trying to find paired products that are often purchased together by the same user, such as wine and bottle openers, chips and beer, etc..
Write a query to find the top five paired products and their names.
Notes:
For the purposes of satisfying the test case, p2 should be the item that comes first in the alphabet.
The qty column represents paired products count
Example:
Input:
transactions table
| Column | Type |
|---|---|
id |
INTEGER |
user_id |
INTEGER |
created_at |
DATETIME |
product_id |
INTEGER |
quantity |
INTEGER |
products table
| Column | Type |
|---|---|
id |
INTEGER |
name |
VARCHAR |
price |
FLOAT |
Output:
| Column | Type |
|---|---|
p1 |
VARCHAR |
p2 |
VARCHAR |
qty |
INTEGER |
.
.
.
.
.
.
.
.
.
Comments