Skip to content

Instantly share code, notes, and snippets.

@mkolb
Created April 30, 2015 21:49
Show Gist options
  • Save mkolb/7dccad7454e86f8e5987 to your computer and use it in GitHub Desktop.
Save mkolb/7dccad7454e86f8e5987 to your computer and use it in GitHub Desktop.
All moodle courses, ordered by enrollment size
SELECT course.fullname AS course, COUNT(course.id) AS students FROM mdl_role_assignments AS asg
JOIN mdl_context AS context ON asg.contextid = context.id AND context.contextlevel = 50 JOIN mdl_user AS u ON u.id = asg.userid JOIN mdl_course AS course ON context.instanceid = course.id WHERE asg.roleid = 5 GROUP BY course.id ORDER BY COUNT(course.id) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment