Tuesday, February 25, 2014

A SQL script to count the number of assignments per course

My customer likes things like this, to quantify things.  He likes charts that show progress, % of course complete, current grade....stuff that administrators ask for, not things that really are reflective of how the learning is going, but rather on how to report numbers, percentages, scores....things that well, quantify so we can report things about ourselves, like how many students, average scores, time in class etc etc, but, I digress.  Sorry.

My customer asks me if I had a report that lists the number of assignments in each course.  I thought, well, not really, but I think I could come up with some SQL that would do that.

No details - by omitting details, we can create a nice summary report. A report like this

courseid - course name - count of assignments in course

SQL to create report

SELECT  DISTINCT a.course, c.fullname as coursename, tempTable.count_of_assignments
 FROM mdl_assignment a

 INNER JOIN
    (
        SELECT  course, count(*) as count_of_assignments
        FROM mdl_assignment
        GROUP BY course
    )
    tempTable
   
    ON a.course = tempTable.course
    INNER JOIN mdl_course c on c.id = a.course
   
    ORDER BY coursename
 Nice.


No comments:

Post a Comment