Welcome to Subscribe On Youtube

3521. Find Product Recommendation Pairs

Description

Table: ProductPurchases

+-++
\| Column Name \| Type \| 
+-++
\| user_id     \| int  \|
\| product_id  \| int  \|
\| quantity    \| int  \|
+-++
(user_id, product_id) is the unique key for this table.
Each row represents a purchase of a product by a user in a specific quantity.

Table: ProductInfo

+-++
\| product_id  \| int     \|
\| category    \| varchar \|
\| price       \| decimal \|
+-+++++++-+
\| product1_id \| product2_id \| product1_category \| product2_category \| customer_count \|
+-+-+-+-+-+

Explanation:

  • Product pair (101, 102):
    • Purchased by users 1, 2, and 4 (3 customers)
    • Product 101 is in Electronics category
    • Product 102 is in Books category
  • Product pair (101, 103):
    • Purchased by users 1, 3, and 4 (3 customers)
    • Product 101 is in Electronics category
    • Product 103 is in Clothing category
  • Product pair (102, 104):
    • Purchased by users 2, 4, and 5 (3 customers)
    • Product 102 is in Books category
    • Product 104 is in Kitchen category

The result is ordered by customer_count in descending order. For pairs with the same customer_count, they are ordered by product1_id and then product2_id in ascending order.

</div>

Solutions

Solution 1

All Problems

All Solutions