[英]Retrieve another data from mySQL for item recommendation
Basically I am currently doing a recommendation system for my website 基本上我正在为我的网站做一个推荐系统
I have 4 tables in mySQL database: 我在mySQL数据库中有4个表:
Users 用户
category 类别
item 项目
transaction 交易
So this is how it I want it works, 所以这就是我想要的方式,
userID 1(Kyle) bought Laptop(ItemID 1), Mouse(ItemID 2), and Battery(ItemID 4) userID 1(Kyle)购买了笔记本电脑(ItemID 1),鼠标(ItemID 2)和电池(ItemID 4)
userID 2(Steven) bought Laptop(itemID 1) userID 2(Steven)购买了笔记本电脑(itemID 1)
userID 3(Jonathan) bought Mouse(ItemID 2), Battery(ItemId 4), and Mousepad(ItemID 3) userID 3(Jonathan)购买了鼠标(ItemID 2),电池(ItemId 4)和Mousepad(ItemID 3)
I want the system to recommend itemID 2(Mouse), itemID4(Battery), and ItemID 3 (Mousepad) to userID 2(Steven) 我希望系统将itemID 2(鼠标),itemID4(电池)和ItemID 3(鼠标垫)推荐给userID 2(史蒂文)
Any helps given are highly appreciated. 给予的任何帮助都非常感谢。 Thanks
谢谢
What the query does is get the All UserID's
which bought the ItemID=2
. 查询的作用是获取购买
ItemID=2
的All UserID's
。 And then Get the ItemID
bough by those users. 然后由这些用户获取
ItemID
bough。 and then apply the filter to remove the ItemId =2
from the result.Try this. 然后应用过滤器从结果中删除
ItemId =2
尝试此操作。
Select distinct ItemID
FROM transaction
where UserID IN (Select userID FROM Transaction where itemID = 2 )
AND ItemID <> 2
Like this 像这样
SELECT
i.itemID,
i.name,
u.username
FROM transaction
INNER JOIN user u ON (u.userID = t.userID)
WHERE u.userID = 2
Then you have to work with your language to convert the result to a readable line. 然后,您必须使用您的语言将结果转换为可读行。
Else you'll have to look for "PIVOT" to convert multiple bought items (multiple lines) to a single line. 否则,你将不得不寻找“PIVOT”将多个购买的物品(多行)转换成一行。
An other solution would be to use a transaction with mssql, allowing to parse the results and return a single line. 另一种解决方案是使用mssql的事务,允许解析结果并返回单行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.