mysql受欢迎吗_MYSQL按喜欢/不喜欢和受欢迎程度排序

bd96500e110b49cbb3cd949968f18be7.png

I have table of comments which includes likes and dislikes, now i have problem with proper order..

Actually my system shows comments with greatest amount of likes on top.

I'm looking for something like system in youtube.

It means that comment with 100like/100dislikes is higher in order than 1/1..

I hope this is understandable :)

解决方案

This is classic problem how to rank upvote/downvote, plus/minus, like/dislike and so on. There are a few possible solutions but they may give wrong result in specific conditions.

I strongly recommend reading and using ordering like in

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

tWymo.png

Sample code (you can easily adapt it for your needs):

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值