Skip to content

Instantly share code, notes, and snippets.

@mikehas
Created August 1, 2012 07:22
Show Gist options
  • Save mikehas/3224507 to your computer and use it in GitHub Desktop.
Save mikehas/3224507 to your computer and use it in GitHub Desktop.
Counts the number of active instructors in moodle.
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 = 'Instructor'
-- 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