0

これが私のコードです。動作していますが、非常に遅いです:

    $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採点の有無にかかわらず、すべてのユーザーの参加を表します。

結果のセットの数値のみに関心があります。これら 2 つの MySQL 呼び出しを、2 つの数値gradedとを返す単一の呼び出しに結合できますtotalか?

4

2 に答える 2

0

次の形式のクエリを使用できます。

Select
( 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']))) gradeCount,

(SELECT posts.userid
                        FROM uv_forum_posts posts
                        WHERE posts.discussion = :discussion_id
                        GROUP BY userid,
                        array(':discussion_id' => $discussion['id'])))totalCount
于 2013-05-07T04:53:22.853 に答える