Thanks, your method is useful!
But I have one more problem to solve.
When I display the results of the following
SQL, I found that only a part of the members will display the results. Do you know where my code went wrong?
SELECT
cs.name,
gi.itemname,
gg.finalgrade,
CASE WHEN qz.name IS NOT NULL THEN CONCAT('http://XXX=', cm.id) ELSE NULL END AS url
FROM mdl_course_modules_completion cmc
JOIN mdl_user u ON cmc.userid = u.id
JOIN mdl_course_modules cm ON cmc.coursemoduleid = cm.id
JOIN mdl_course c ON cm.course = c.id
JOIN mdl_modules m ON cm.module = m.id
LEFT JOIN mdl_grade_items gi ON gi.courseid= c.id AND gi.itemmodule= m.name AND gi.iteminstance=cm.instance
LEFT JOIN mdl_grade_grades gg ON gg.userid=u.id AND gg.itemid=gi.id
INNER JOIN mdl_context AS ctx ON ctx.contextlevel = 70 AND ctx.instanceid = cm.id
INNER JOIN mdl_quiz AS qz ON m.name = 'quiz' AND cm.instance = qz.id
JOIN mdl_course_sections cs ON cs.id = cm.section
WHERE u.username = 943751