小编use*_*752的帖子

计算评分系统的平均值

我想计算评级系统的平均值,但我在 innodb 中有普通表,在 json 中有一个列,名称为:“评论”,结构如下:

{"comments": 
    [
        {"name": "Jonh", "text": "nice phone", "star": 4}, 
        {"name": "igon", "text": "not good", "star": 2}, 
        {"name": "marco", "text": "i not like this", "star": 3},
        {"name": "david", "text": "good product", "stelle": 5}
    ]
}
Run Code Online (Sandbox Code Playgroud)

现在我需要计算平均星级。它是在 sql 中还是在 php 中?在 sql 中我不知道如何,在 php 中我有查询只提取全明星的问题,例如:

$reviews_nn = $rowprod["reviews"];
$reviews = json_decode($reviews_nn,true);
$max = 0;
$n = 0;
foreach ($reviews[comments][star] as $rate => $count) {
    echo 'Seen ', $count, ' ratings of ', $rate, "\n";
    $max += $rate …
Run Code Online (Sandbox Code Playgroud)

php mysql rating

4
推荐指数
1
解决办法
8698
查看次数

标签 统计

mysql ×1

php ×1

rating ×1