我想构建一个查询来随机显示来自 ITEM 表的用户的项目,但根据项目类别在 PREFERENCE 表中存在的次数(更大的偏差)。类别必须自动添加到查询中。
ITEM TABLE
Itemname Category Id
'item1', '20081'
'item2 ', '15032'
'items3', '20081'
'item4', '20081'
PREFERENCE TABLE
Userid, Categoryname, Categoryid
'79', 'Everything Else', '15032'
'146', 'Antiques', '20081'
'79', 'Antiques', '20081'
'79', 'Antiques', '20081'
'79', 'Antiques', '20081'
在简单的意义上它是这样的
SELECT * FROM `ex`.`item` where category_id=20081 or category_id=79 /*there rest to be added automatically and also with the bias depending on the count in preference */order by rand();