SQL / MySQL Intermediate Code only

Average quiz score per course with JOIN and GROUP BY

Combine two tables and summarise the results.

Updated 5 Oct 2026 9 lines 1 min read

JOIN matches each attempt to its course; GROUP BY then gives one row per course with its average.

database.sql
Download
SELECT c.title           AS course,
       COUNT(a.id)       AS attempts,
       ROUND(AVG(a.score), 1) AS average_score
FROM courses c
JOIN quiz_attempts a ON a.course_id = c.id
WHERE a.status = 'submitted'
GROUP BY c.id, c.title
HAVING COUNT(a.id) >= 5
ORDER BY average_score DESC;
Code only · preview unavailable SQL is shown for reading. Try it in your own MySQL database (for example in phpMyAdmin); it is never run against this site.
Hi there! đź‘‹ Have a question about the courses or joining the class? Ask me.