Para gerar diretamente na base de dados a lista de alunos que já completaram o curso com comando SQL, basta executa o seguinte camando:
SELECT DISTINCT ue.id,en.courseid AS courseid,u.firstname,u.lastname,u.email,r.name AS rolename,r.shortname AS roleshortname,en.status AS methodstatus,en.enrol AS methodplugin,ue.status AS enrolstatus,ue.timestart,ue.timeend,p.timecompleted,c.fullname AS course, c.id AS courseid FROM mdl_role_assignments rs INNER JOIN mdl_user u ON u.id=rs.userid INNER JOIN mdl_role r ON rs.roleid=r.id INNER JOIN mdl_context e ON rs.contextid=e.id INNER JOIN mdl_enrol en ON e.instanceid=en.courseid INNER JOIN mdl_user_enrolments ue ON en.id=ue.enrolid INNER JOIN mdl_course_completions p ON p.course=en.courseid INNER JOIN mdl_course c ON c.id=en.courseid WHERE e.contextlevel=50 AND rs.userid=ue.userid AND p.userid=rs.userid AND p.timecompleted > 0 ORDER BY p.timecompleted DESC