Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Jan 23, 2015

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
You can’t perform that action at this time.