List of courses with number of enroll and completed

List of courses with number of enroll and completed

by DarioDN DN -
Number of replies: 5

Dear All, could you help me to define a sql query to obtain a list of course with these columns?

I'm using the following query to obtain the first value, but how to add the second one (at least)?

SELECT c.fullname AS 'Course Name'
       ,COUNT(u.username) AS '# of Users'
 FROM mdl_role_assignments AS r
   JOIN mdl_user AS u on r.userid = u.id
   JOIN mdl_role AS rn on r.roleid = rn.id
   JOIN mdl_context AS ctx on r.contextid = ctx.id
   JOIN mdl_course AS c on ctx.instanceid = c.id
 WHERE rn.shortname = 'student'
 GROUP BY c.fullname, rn.shortname


thank you

Average of ratings: -
In reply to DarioDN DN

Re: List of courses with number of enroll and completed

by Randy Thornton -
Picture of Documentation writers
You will find a query to do that here: https://docs.moodle.org/310/en/ad-hoc_contributed_reports#List_Students_with_enrollment_and_completion_dates_in_current_course along with other similar queries related to course completion.
Average of ratings: Useful (1)
In reply to Randy Thornton

Ri: Re: List of courses with number of enroll and completed

by DarioDN DN -
Dear Randy Thank you.
I've already read that page but I have an issue to insert, in my query, only a total count of "completed", for each row/course.
I'd like to have:

Course Title | Total Enrolled Students | Total Completed
Course Title 2 | Total Enrolled Students | Total Completed

Can you assist me with that?
Thank you
In reply to DarioDN DN

Re: Ri: Re: List of courses with number of enroll and completed

by Randy Thornton -
Picture of Documentation writers
You usually want to use the COUNT() function to do that. If is often used with a GROUP BY.

There are some examples in the Ad-hoc page where there enrolment counts per course, similar to what you are doing, like this one: https://docs.moodle.org/310/en/ad-hoc_contributed_reports#Enrolment_count_in_each_Course. Take a look there for similar ones. You can use that same process to get completion totals too.
Average of ratings: Useful (1)
In reply to Randy Thornton

Ri: Re: Ri: Re: List of courses with number of enroll and completed

by DarioDN DN -
Yes, I know that I need of "count" function but I don't know how to insert it in my query, considering that it needs to search in a different "from" table.