我有一个包含喜欢和不喜欢的评论表,现在我对正确的顺序有疑问..
实际上,我的系统会在顶部显示点赞次数最多的评论。
我在 youtube 中寻找类似系统的东西。
表示100like/100dislikes的评论比1/1高..
我希望这是可以理解的:)
最佳答案
这是如何对赞成票/反对票、加号/减号、喜欢/不喜欢等进行排名的经典问题。有一些可能的解决方案,但在特定条件下它们可能会给出错误的结果。
我强烈建议阅读和使用 How Not To Sort By Average Rating
中的排序方式
PROBLEM:
You need some sort of "score" to sort by.
WRONG SOLUTION #1: Score = (Positive ratings) - (Negative ratings)
WRONG SOLUTION #2: Score = Average rating = (Positive ratings) / (Total ratings)
CORRECT SOLUTION: Score = Lower bound of Wilson score confidence interval for a Bernoulli parameter
示例代码(您可以根据需要轻松调整它):
SELECT id, ((positive + 1.9208) / (positive + negative) -
1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) /
(positive + negative)) / (1 + 3.8416 / (positive + negative))
AS ci_lower_bound
FROM your_tab
WHERE positive + negative > 0
ORDER BY ci_lower_bound DESC;
关于php - MYSQL 按喜欢/不喜欢和受欢迎程度排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34111209/