Last active
September 24, 2015 20:26
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.