我有用户可以评价的体育赛事。所有数据都存储在Mysql数据库中。
评分表:
rating_id PK
organization float //subrating
value_for_money float //subrating
fun_factor float //subrating
facilities float //subrating
event_id int
user_id int
事件表:
event_id PK
event_name varchar
有没有一种方法可以使用 Mysql 查询来连接表并对它们进行排序,以便我可以检索子评级的平均评级最高的 3 个事件?
最佳答案
我想可能是这样:
SELECT e.event_id, event_name, avg_rating
FROM Event_table e
JOIN (
SELECT event_id, MAX((organization+value_for_money+fun_factor+facilities)/4) avg_rating
FROM Ratings_table
GROUP BY event_id
ORDER by avg_rating DESC
LIMIT 3) r
ON e.event_id = r.event_id
关于php - 如何检索 MySQL 中评分最高的 3 个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19156723/