SQL query for Courses Enrolment on Moodle

后端 未结 5 583
清歌不尽
清歌不尽 2020-12-30 09:31

I was looking for the proper SQL queries for retrieving all students enrolled in a certain course, or all courses a certain student has enrolled in, on Moodle

5条回答
  •  粉色の甜心
    2020-12-30 10:04

    The following code generates a list of all your courses together with how many students are enrolled in each. Useful to find out if you have any courses with no one enrolled.

    My Answer :

    SELECT cr.SHORTNAME, 
           cr.FULLNAME, 
           COUNT(ra.ID) AS enrolled 
    FROM   `MDL_COURSE` cr 
           JOIN `MDL_CONTEXT` ct 
             ON ( ct.INSTANCEID = cr.ID ) 
           LEFT JOIN `MDL_ROLE_ASSIGNMENTS` ra 
                  ON ( ra.CONTEXTID = ct.ID ) 
    WHERE  ct.CONTEXTLEVEL = 50 
           AND ra.ROLEID = 5 
    GROUP  BY cr.SHORTNAME, 
              cr.FULLNAME 
    ORDER  BY `ENROLLED` ASC 
    

提交回复
热议问题