我现在正在使用slope One进行推荐。
如何从结果中排除访问过的项目?
我不能简单地通过not in (visited_id_list)来过滤那些访问过的用户,因为这对老用户来说会有可伸缩性问题!
我想出了一个没有not in的解决方案:
select b.property,count(b.id) total from propertyviews a
left join propertyviews b on b.cookie=a.cookie
left join propertyviews c on c.cookie=0 and b.property=c.property
where a.property=1 and a.cookie!=0 and c.property is null
group by b.property order by total;发布于 2010-01-18 22:06:17
说真的,如果您使用的是MySQL,请查看12.2.10.3. Subqueries with ANY, IN, and SOME
例如:
SELECT s1 FROM t1 WHERE s1 IN (SELECT s1 FROM t2);这在我看过的所有MySQL版本中都可用,尽管手册中的章节编号在旧版本中有所不同。
编辑以回应OP的评论:
SELECT id FROM t1 WHERE ... AND NOT id IN (SELECT seen_id FROM user_seen_ids where user = ? )这样的东西怎么样?这种形式避免了在SQL语句中传递数以千计的is。https://stackoverflow.com/questions/2085233
复制相似问题