Hi,
I'm trying to type up a SQL to get a list with users which completed a course, incl. all final course grades (if available), not matter if the user is still enrolled or unenrolled in the course.
That's what I have so far:
SELECT DISTINCT u.username, u.id, u.lastname, u.firstname, c.fullname, ROUND(gg.finalgrade, 0) FROM m_grade_grades_history gg, m_grade_items gi, m_course c,
m_course_completions cc, m_user u
WHERE gg.userid = u.id AND gi.id = gg.itemid AND gi.itemtype = 'course' AND c.id = gi.courseid
AND cc.userid = u.id AND CC.TIMECOMPLETED > 0
ORDER BY c.fullname, u.username;
My problem is that some users appear more than once in the result set:
student01 101 Wilman (test01) Susan Fire Extinguisher Training 50
student01 101 Wilman (test01) Susan Fire Extinguisher Training 75
student01 101 Wilman (test01) Susan Fire Extinguisher Training 100
student01 101 Wilman (test01) Susan Fire Extinguisher Training
Why does that happen and how can I get the correct, final grade?
I do not want to include a "WHERE finalgrade > 0" because some of our courses don't have final grades. But I want these ungraded user to appear in the list as well, once they completed the course.
Thanks