php - MYSQL 按喜欢/不喜欢和受欢迎程度排序

标签 php html mysql sql mysqli

我有一个包含喜欢和不喜欢的评论表,现在我对正确的顺序有疑问..

实际上,我的系统会在顶部显示点赞次数最多的评论。

我在 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

enter image description here

示例代码(您可以根据需要轻松调整它):

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/

相关文章:

PHP 在 URL 中发布而不使用 GET

php - 为什么我需要 "&"?

php - 当达到第 50 条记录时删除所有记录 - sql/php

html 和 css 边距自动错误

mysql - 检索缺失的列值

mysql - 如何在不硬编码的情况下提前两个月引入日历类型的数据?

php - 使用 MySQL LOAD_FILE() 将 XML 添加到列

html - 背景图像不是来自 joomla 2.5 中的 css

android - Retrofit 2.0 解析 HTML

php - 无法使用 php 的 PDO 将数据插入数据库