Problem Description
I got this SQL code from Moodle [SQL scripts][1] How to make the result to include all itemnames whether it has a score or not? **prefix_grade_grade** table contains the score
**prefix_grade_items** table has the itemnames
Not sure what vendor, these scripts are used in Moodle LMS open source system
SELECT u.firstname AS 'Name' , u.lastname AS 'Surname', c.fullname AS 'Course', cc.name AS 'Category',
CASE WHEN gi.itemtype = 'Course'
THEN c.fullname + ' Course Total'
ELSE gi.itemname
END AS 'Item Name', ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS Percentage
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE gi.courseid = c.id AND gi.itemname != 'Attendance' AND gi.itemmodule != 'scorm'
ORDER BY `Name` ASC
[1]: https://docs.moodle.org/28/en/ad-hoc_contributed_reports#Learner_report_by_Learner_with_grades
[2]: https://i.sstatic.net/qeHIW.jpg
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?