Para mapear a nota dos alunos que tiveram a matrícula excluída do curso da Plataforma Moodle, execute no banco o seguinte comando SQL:
SELECT u.id, u.firstname,u.lastname,u.username AS CPF, u.email,g.finalgrade FROM mdl_grade_items i INNER JOIN mdl_grade_grades g ON i.id=g.itemid INNER JOIN mdl_user u ON u.id=g.userid WHERE i.itemtype = 'course' AND i.courseid=? AND g.userid NOT IN (SELECT DISTINCT rs.userid FROM mdl_role_assignments rs INNER JOIN mdl_context e ON rs.contextid=e.id WHERE e.contextlevel=50 AND rs.roleid=5 AND e.instanceid=?)
Para o parâmetro id do curso em i.courseid=? e e.instanceid=?