MySQL推荐引擎查询

时间:2013-06-15 15:28:17

标签: mysql recommendation-engine

我正在尝试编写一个非常基本的推荐/追加销售查询,我可以返回其他人购买的产品列表,这些产品与当前用户购买的产品处于相同的“订单”,但不是是同一种产品。

我解释这个的简单方法是:

  • 用户A购买扳手和演习
  • 用户B购买钻头和一些螺钉
  • 用户C买了一些钉子和一把扳手

所以我想向用户A推荐螺钉和钉子。

我有产品表,Invoice_Header表和Invoice_Line表。

到目前为止我所拥有的(这可能会更好地解释我的要求)。

SELECT
    Products.Product_Code,
    Products.Full_Description,
    count(Products.id) as hits
FROM
    Products as Products,
    Invoice_Header as Invoice_Header,
    Invoice_Line as Invoice_Line,
    Invoice_Line as Invoice_Line_Common,
    Invoice_Line as Invoice_Line_Products
WHERE
    Invoice_Header.account_number = 765
    AND
    Invoice_Line.invoice_num = Invoice_Header.invoice_number
    AND
    Invoice_Line_Common.product_code = Invoice_Line.product_code
    AND
    Invoice_Line_Products.invoice_num = Invoice_Line_Common.invoice_num
    AND
    Products.Product_Code = Invoice_Line_Products.product_code
    AND
    Products.Product_Code != Invoice_Line.product_code
group by Products.Product_Code
order by hits
limit 0,10

现在,这就像狗一样,因为我有80万张发票行。

有没有人建议更快地这样做?

0 个答案:

没有答案