【问题标题】:calculate the average rating on a review system计算评论系统的平均评分
【发布时间】:2014-03-23 04:19:21
【问题描述】:

需要计算评论系统的平均评分
我的评论有 3 个项目:comfortpriceclean - 允许在 0 到 5 之间

INSERT INTO review (id, comfort, price, cleanliness) values ​​(1, 3, 5, 2); INSERT INTO review (id, comfort, price, cleanliness) values ​​(2, 2, 4, 4);

当我列出评论的内容时,我必须计算每个项目的平均值...
我最好将媒体保存在单独的表格中以避免每次都需要计算?

insert into company (id, rate_ comfort, rate_ price, rate_ cleaning, description) values ​​(1, 3, 5, 3, 'text description');

【问题讨论】:

    标签: php review rate


    【解决方案1】:
    SELECT AVG(comfort), AVG(price), AVG(cleanliness)
    FROM review
    

    是你真正需要的。如果没有任何分组/where 子句,将计算表中所有记录的平均值。

    【讨论】:

    • 非常感谢,我会简单测试一下,我觉得就是这样……会解决一个大问题
    猜你喜欢
    • 2017-10-11
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 2011-10-24
    • 2011-08-06
    • 2013-07-31
    相关资源
    最近更新 更多