MYSQL评级算法

发布于 2024-11-04 07:43:18 字数 2241 浏览 0 评论 0原文

我有一个 MYSQL 表,它存储用户每个事件的评级,事件表中的 1-10 称为 event_ rating。我试图找到的是基于投票数和评级的最准确评级,如下所示:

SELECT
 c.userid,
 c.user_name,
 COUNT(d.event_rating) AS votesCount,
 AVG(d.event_rating) AS votesAvg,
 SUM(d.event_rating) AS tsum,
 COUNT(d.event_rating)*AVG(d.event_rating)/COUNT(d.event_rating) as totalRating
FROM events d JOIN users c ON d.userid = c.userid WHERE (d.userid = '2') GROUP BY d.userid ORDER BY totalRating DESC

我为用户添加了两个虚拟评级,一个评级为 10,另一个评级为 5。

结果如下

 userid     user_name      votesCount       votesAvg    tsum      totalRating
   2    Rahul Khanna         2            7.5000        15        7.50000000

:准确吗,我计算得对吗?

--- 编辑 ---

发布更多结果

使用 COUNT(d.event_ rating)*AVG(d.event_ rating)/COUNT(d.event_ rating) as TotalRating

userid  user_name   votesCount  votesAvg    tsum    totalRating
2      Rahul Khanna     2       7.5000       15      7.50000000
1      Rita Agnihotri   9       4.8889       44      4.88888889
3      Daniel Springs   4       3.5000       14      3.50000000
4      Roger Myers      6       3.5000       21      3.50000000
5      Chun Tanakat     3       3.0000       9       3.00000000

使用 COUNT(d.event_ rating)*AVG(d.event_ rating) 作为totalRating

userid  user_name   votesCount  votesAvg    tsum    totalRating
1      Rita Agnihotri   9       4.8889       44      44.0000
4      Roger Myers      6       3.5000       21      21.0000
2      Rahul Khanna     2       7.5000       15      15.0000
3      Daniel Springs   4       3.5000       14      14.0000
5      Chun Tanakat     3       3.0000       9       9.0000

--- 更多 ---

<强>我应该使用下面的?

COUNT(d.event_rating)*AVG(d.event_rating)/10 as totalRating

我需要的是一种准确的方法来计算总评分,同时将 votesCount 考虑在内,并且评分必须在 1-10 之间。

--- 更多详细信息 ---

我有一个表用户另一个事件,用户可以添加新事件并对这些事件进行评分。事件表有一个 eventID、userid、event_ rating 列。因此,每个事件都可以保存用户创建的事件的评级。我想要的是计算所有事件评级以获得该用户的最大(总)评级。我希望无论用户创建了多少事件,总评分都在 1-10 之间,并且不超过 10。这可能吗?如果没有任何解决方案或想法?

感谢您的阅读:)

I have a MYSQL table which stores a rating for each event of a user, 1-10 in the events table called event_rating. What i'm trying to find is the highest accurate rating based on the number of votes and rating like this:

SELECT
 c.userid,
 c.user_name,
 COUNT(d.event_rating) AS votesCount,
 AVG(d.event_rating) AS votesAvg,
 SUM(d.event_rating) AS tsum,
 COUNT(d.event_rating)*AVG(d.event_rating)/COUNT(d.event_rating) as totalRating
FROM events d JOIN users c ON d.userid = c.userid WHERE (d.userid = '2') GROUP BY d.userid ORDER BY totalRating DESC

I added two dummy ratings for a user, one with a rating of 10 and another with 5.

The results are below:

 userid     user_name      votesCount       votesAvg    tsum      totalRating
   2    Rahul Khanna         2            7.5000        15        7.50000000

Is that accurate, and am i calculating it right?

--- EDIT ---

Posting Some more results

USING COUNT(d.event_rating)*AVG(d.event_rating)/COUNT(d.event_rating) as totalRating

userid  user_name   votesCount  votesAvg    tsum    totalRating
2      Rahul Khanna     2       7.5000       15      7.50000000
1      Rita Agnihotri   9       4.8889       44      4.88888889
3      Daniel Springs   4       3.5000       14      3.50000000
4      Roger Myers      6       3.5000       21      3.50000000
5      Chun Tanakat     3       3.0000       9       3.00000000

USING COUNT(d.event_rating)*AVG(d.event_rating) as totalRating

userid  user_name   votesCount  votesAvg    tsum    totalRating
1      Rita Agnihotri   9       4.8889       44      44.0000
4      Roger Myers      6       3.5000       21      21.0000
2      Rahul Khanna     2       7.5000       15      15.0000
3      Daniel Springs   4       3.5000       14      14.0000
5      Chun Tanakat     3       3.0000       9       9.0000

--- MORE ---

Should i be using the below instead?

COUNT(d.event_rating)*AVG(d.event_rating)/10 as totalRating

What i need is an accurate way to calculate the total rating, putting votesCount into consideration as well and that the rating has to be between 1-10.

--- MORE DETAIL ---

I have one table Users another Events, user is able to add new events and rate those events. The Events table has a eventID, userid, event_rating column. So each event can hold a rating for the event the user has created. What i want is to calculate all the events rating to get the max (total) rating for that user. I want the total rating i get to be between 1-10 and not exceed over 10 no matter how many events the user has created. Is that possible? if not any solutions or ideas?

Thanks for reading :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风流物 2024-11-11 07:43:18

这个愚蠢的查询是什么?

COUNT(d.event_rating)*AVG(d.event_rating)/COUNT(d.event_rating) as totalRating

这不是

(a*b)/a ,它总是 b

你必须只获取 AVG(d.event_ rating)

你真正想要什么?

What is this silly piece of query??

COUNT(d.event_rating)*AVG(d.event_rating)/COUNT(d.event_rating) as totalRating

This is nothing

(a*b)/a which is always b

you have to just fetch AVG(d.event_rating)

what do you want really ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文