我有一个名为“rooms”的表格,其中包含“rid”(房间ID),“评级”(从0到10)的行“id”col和“visits”。
我想根据加权评分获得顶级房间忽略 0票,如下公式:
((total_avg_votes * total_avg_rating)+(specific_votes * specific_avg_rating))/(total_avg_votes + speicific_votes)
我有这个公式,但它也不会得到我的评价,也不会忽略0的投票:
SELECT rooms.id, t1.count FROM rooms INNER JOIN ( SELECT rid, COUNT(rating) as count
FROM
visits
WHERE visits.rating <> 0
GROUP BY visits.rid) AS t1 ON rooms.id = t1.rid