Skip to content

Commit

Permalink
[#131] Optimise user attempts sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Mar 30, 2023
1 parent 1b8098a commit 4420bbc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions classes/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,14 @@ private function get_quiz_attempts(int $quizid): \stdClass {
$finishedusers = array();

$sql = 'SELECT userid, state
FROM {quiz_attempts}
WHERE id IN (
SELECT MAX(id)
FROM {quiz_attempts}
WHERE quiz = ?
GROUP BY userid)';
FROM {quiz_attempts} qa
JOIN (
SELECT MAX(id) id
FROM {quiz_attempts}
WHERE quiz = ?
GROUP BY userid)
AS qb
ON qa.id = qb.id';

$params = array($quizid);

Expand Down

0 comments on commit 4420bbc

Please sign in to comment.