Gradebook database

Gradebook database

min ihope發表於
Number of replies: 4
hi, can someone help me? I have some question about the gradebook database. 1.in the mdl_grade_grades table,what' s the itemid mean? how can this table ralated to the course?in other word , how can I know the final grade is belong to the course. Thanks very much!
In reply to min ihope

Re: Gradebook database

Wes Matchett發表於

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.

In reply to Wes Matchett

Re: Gradebook database

Wes Matchett發表於

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:

SQL results

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?

In reply to Wes Matchett

Re: Gradebook database

Wes Matchett發表於

I dug a bit more by adding mgi.* to the field list and found that the mgi.itemtype field seems to indicate the record type and by adding

mgi.itemtype = 'course' 

to the where clause it only returns the final grade for each student for each course.