Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Last active September 24, 2015 20:26
Show Gist options
  • Save RyanNutt/13809e477f625e2cf5f8 to your computer and use it in GitHub Desktop.
Save RyanNutt/13809e477f625e2cf5f8 to your computer and use it in GitHub Desktop.
MySQL query for ad-hoc Moodle queries to count quizzes - http://www.nutt.net/2015/01/22/pulling-grades-moodle-quizzes/
SELECT u.lastname, u.firstname, u.idnumber,
(
SELECT COUNT(*)
FROM prefix_quiz_attempts attempts
JOIN prefix_quiz quiz
ON attempts.quiz=quiz.id
JOIN prefix_course_modules cm
ON cm.instance=quiz.id
WHERE
attempts.userid=u.id
AND state='finished'
AND cm.id=:module_id
AND (attempts.sumgrades / quiz.sumgrades * quiz.grade) >= :minimum_grade
) AS quizcount
FROM prefix_user u
HAVING quizcount>0
ORDER BY u.lastname ASC, u.firstname ASC
@RyanNutt
Copy link
Author

Quick update. Instead of always multiplying the points times 100 (last line in the subquery) it's multiplying times the total points available for the quiz. If it's 100, it won't make any difference. But that way, if you have a quiz that's not out of 100 points the math will still work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment