Created
August 1, 2012 07:23
-
-
Save mikehas/3224526 to your computer and use it in GitHub Desktop.
Counts the number of active students in moodle.
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 count(distinct(ue.userid)) from mdl_user_enrolments ue | |
join mdl_enrol e on (ue.enrolid=e.id) | |
join mdl_course c on (c.id=e.courseid) | |
join (select * from mdl_context where contextlevel=50) ct on (ct.instanceid=c.id) | |
join (select * from mdl_role_assignments where component='enrol_engine') ra on (ra.contextid=ct.id and ue.userid=ra.userid) | |
join mdl_role r on (ra.roleid = r.id) | |
where c.idnumber like '%-<insert_quarter_suffix_here>' | |
and c.visible=1 | |
and ue.status=0 | |
and r.name = 'Student' | |
-- Here, "engine" is used to only select automatically provisioned users | |
-- and e.enrol like 'engine' | |
order by c.idnumber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment