I have the same questions and after looking at the schema and table descriptions, I have concluded:
mdl_grade_grades.itemid -> mdl_grade_items.id
and
mdl_grade_items.courseid -> mdl_course.id
If this is wrong I'd like someone in the know to correct it. The following SQL will return the student name, course and grade:
SELECT concat(mu.firstname, " ", mu.lastname) name,
mc.fullname course,
mgg.finalgrade grade
FROM mdl_grade_grades mgg
JOIN mdl_user mu ON mgg.userid = mu.id
JOIN mdl_grade_items mgi ON mgg.itemid = mgi.id
JOIN mdl_course mc ON mgi.courseid = mc.id;
Hope this helps.
I don't get expected results from this SQL. I get multiple records per class per student. I added selection of a specific user:
SELECT concat(mu.firstname, " ", mu.lastname) name,
mc.fullname course,
mgg.finalgrade grade
FROM mdl_grade_grades mgg
JOIN mdl_user mu ON mgg.userid = mu.id
JOIN mdl_grade_items mgi ON mgg.itemid = mgi.id
JOIN mdl_course mc ON mgi.courseid = mc.id
where mgg.userid = '136';
And I see this:
90.65 is the correct 'Course Total' grade for this student in the 'grader report'. How do I select just that record in the SQL?