这是我的代码,可以正常工作,但速度很慢:
$graded = R::getAll("SELECT posts.id, posts.discussion, rating.rating, rating.itemid
FROM uv_forum_posts posts
JOIN uv_rating rating ON ( posts.id = rating.itemid )
WHERE posts.discussion = :discussion_id
GROUP BY posts.userid",
array(':discussion_id' => $discussion['id']));
$total = R::getAll("SELECT posts.userid
FROM uv_forum_posts posts
WHERE posts.discussion = :discussion_id
GROUP BY userid",
array(':discussion_id' => $discussion['id']));
$percentages[] = count($graded) / count($total) * 100;
$graded
表示所有有评分的行。
$total
代表所有用户参与,无论是否评分。
我只对结果集的数值感兴趣,我可以将这两个 MySQL 调用组合成一个返回两个数字的调用graded
吗total
?