douye4254 2013-10-03 10:24
浏览 35
已采纳

我怎样才能重温前3个评级事件MySQL

I have sporting events that users can rate. All data is stored in a Mysql database.

Ratings_table:

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_table:

event_id PK
event_name varchar

Is there a way I can use Mysql query to join the tables and order them so that I can retrieve the 3 events with the highest average rating of the sub ratings?

  • 写回答

3条回答 默认 最新

  • dongyun8891 2013-10-03 10:39
    关注

    I think this may be it:

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法