Hi,
I have very little experience with SQL and was hoping someone on might
be able to help...
I am trying to create a configurable report that simply replicates the
Course Completion report (found in the Course Completion block) for a single
course, but with the addition of some custom user profile fields. So the columns would be:
- idnumber
- firstname
- lastname
- profile_field_employmenttype(Custom user profile field)
- department
- profile_field_dept(Custom user profile field)
- profile_field_subsection(Custom user profile field)
- profile_field_section (Custom user profile
field)
- profile_field_directorate (Custom user profile
field)
- Course completion date
- Course completion status
The SQL I currently have seems to be pulling the right kind of info but
there are issues...
1) The report is returning course completions for all courses across
the site. How can I restrict this so the
report only returns course completions for one course? (the course where I add
the configurable report block)
2) The report is returning 896 records which is not the full number
records I am expecting,
3) I'm getting a lot of duplicated records in the report, by up to 4
times.
Here's my current code:
SELECT u.idnumber AS 'ID' ,
u.firstname AS 'First' , u.lastname AS 'Last',
aa.data AS 'Employment Type', ab.data AS 'Department', ac.data AS
'Dept', ad.data AS 'Sub Section', ae.data AS 'Section', af.data AS
'Directorate', ag.data AS 'Area',
CASE
WHEN gi.itemtype = 'course'
THEN CONCAT(c.fullname, ' -
Total')
ELSE gi.itemname
END AS 'Item Name',
ROUND(gg.finalgrade,2) AS Grade,
FROM_UNIXTIME(gg.timemodified) AS TIME
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_user_info_data AS aa
ON u.ID = aa.userid AND aa.fieldid=1
JOIN prefix_user_info_data AS ab
ON u.ID = ab.userid AND ab.fieldid=2
JOIN prefix_user_info_data AS ac
ON u.ID = ac.userid AND ac.fieldid=3
JOIN prefix_user_info_data AS ad
ON u.ID = ad.userid AND ad.fieldid=4
JOIN prefix_user_info_data AS ae
ON u.ID = ae.userid AND ae.fieldid=5
JOIN prefix_user_info_data AS af
ON u.ID = af.userid AND af.fieldid=6
JOIN prefix_user_info_data AS ag
ON u.ID = ag.userid AND ag.fieldid=7
JOIN prefix_grade_grades AS gg ON gg.userid = u.id AND
gg.finalgrade>10 and gg.finalgrade<100
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
ORDER BY Last
Any help would be greatly appreciated!
Thanks,
Andrew