Mysql
 sql >> Base de données >  >> RDS >> Mysql

trouver des produits que les clients ont achetés ensemble

Essayez ce qui suit :

SELECT c.original_SKU, c.bought_with, count(*) as times_bought_together
FROM (
  SELECT a.sku as original_SKU, b.sku as bought_with
  FROM items a
  INNER join items b
  ON a.order_id = b.order_id AND a.sku != b.sku) c
GROUP BY c.original_SKU, c.bought_with