Site-Wide Grade Report - Sorting

Site-Wide Grade Report - Sorting

by Mykl Belfatto -
Number of replies: 2

I want to sort the report by Company and Course because 1) we distribute reports by Company, and 2) we have students in more than one course.

Here is my SQL

SELECT u.firstname AS 'First' , u.lastname AS 'Last', CONCAT(u.firstname , ' ' , u.lastname) AS 'Display Name',
aa.data AS Company, c.fullname AS Course,
cc.name AS 'Category',
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_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
JOIN prefix_user_info_data AS aa ON u.ID = aa.userid AND aa.fieldid=1

WHERE aa.data != ''

ORDER BY company, course, lastname, firstname


it is sorting by lastname, firstname, then course, ignoring Company

I´ve also tried ORDER BY aa.data, course, lastname, firstnamewith the same result


Any ideas?

Attachment site rpt.png
Average of ratings: -
In reply to Mykl Belfatto

Re: Site-Wide Grade Report - Sorting

by Mykl Belfatto -

I also tried adding a filter for Company.  The field is on the screen, but when I select an item, it has no effect (can you filter with a MENU type field or only TEXT?)

It works when I but in the WHERE clause WHERE aa.data "BRO"


In reply to Mykl Belfatto

Re: Site-Wide Grade Report - Sorting

by Mykl Belfatto -

I worked around this by rewriting the query from the other end.


SELECT data AS 'Company', u.firstname AS 'First' , u.lastname AS 'Last', c.fullname AS Course, cc.name AS 'Category', 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_user_info_data AS ui

JOIN prefix_user AS u ON u.id = ui.id

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 AS c ON c.id = gi.courseid

JOIN prefix_course_categories AS cc ON cc.id = c.category

WHERE ui.data != ''

ORDER BY company, Lastname, firstname, Course


You could also modify this to use the institution field