SELECT pother.id, count(*) as common
FROM product
JOIN category ON product.category = category.id
JOIN product pother ON pother.category = category.id
WHERE product.id = X
GROUP BY pother.id
ORDER BY common DEC LIMIT 10
SELECT id, count(*) as common
FROM product
JOIN category
ON product.category = category.id AND category.id IN (select category FROM product WHERE product.id = X)
GROUP BY id
ORDER BY comm DESC LIMIT 10
1条答案
按热度按时间tyky79it1#
查询将为:
如果
product.category
被索引,并且你把一个产品限制在10个类别,那么它可能不会太糟糕。替代子查询表单
您可以将查询计划编辑到这个答案中吗?