Skip to content

Instantly share code, notes, and snippets.

@mikebuchanon
Created May 3, 2012 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebuchanon/2589794 to your computer and use it in GitHub Desktop.
Save mikebuchanon/2589794 to your computer and use it in GitHub Desktop.
query for final grades in moodle
select mc.shortname as course_Id,mu.username,
case when ABS(ROUND(mgg.finalgrade, 0) - mgg.finalgrade) <= 0.0000005 then cast(mgg.finalgrade as text) else 'Pending...' end as final_grade,
mgi.itemname
from mdl_grade_grades mgg
join mdl_user mu on mgg.userid=mu.id
join mdl_user_enrolments mue on mue.userid=mu.id
join mdl_grade_items mgi on mgg.itemid=mgi.id
join mdl_course mc on mc.id=mgi.courseid
join mdl_enrol me on mue.enrolid=me.id and me.courseid=mc.id
join mdl_role_assignments mra on mu.id=mra.userid
join mdl_role mr on mra.roleid=mr.id
where mc.category = '1' and -- mdl_course_categories.id = '1'; id=1 => name='Spring 2012' as an example
mr.shortname='student' and -- only get people enrolled with a 'student' role in the course
mgi.itemname ilike '%Final%Grade%'; --anything with 'final' and 'grade' in it regardless of case and surrounding text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment