Assistance with SQL Query Extracting Student Scores For Assignments and Courses in Canvas Data 2

MichaelBealATSU
Community Member

The goal is to create a SQL query to extract the student (prefer the student ID), the course, the assignment, and the associated grade.  I have the following query but it is not what I want or need.  I am purposefully limiting it to a particular term but need all of the courses, assignments, scores by student.   

SELECT
u.sortable_name AS student_name
,etd.name AS term_name
,cd.name AS course_name
,cd.course_code AS course_code
,count(a.title)
,sf.score AS assignment_score
FROM enrollments e
JOIN courses cd ON e.course_id = cd.id
JOIN enrollment_terms etd ON cd.enrollment_term_id = etd.id
JOIN assignments a ON cd.id = a.context_id
JOIN users u ON e.user_id = u.id
LEFT OUTER JOIN attachments b ON a.id = b.context_id
LEFT OUTER JOIN quiz_submissions sf ON b.context_id = sf.id
WHERE 1=1
AND (e.type = 'StudentEnrollment'
AND e.workflow_state = 'active')
AND (a.workflow_state = 'published')
AND (cd.course_code like '%CCPA%')
and (etd.name like '%23-24FA-MSPA1%')
group by u.sortable_name
,etd.name
,cd.name
,cd.course_code
,sf.score
 

Has anyone done something like this and if so what did your query look like?  Do you have any examples?

0 Likes