← Back to CTEs
Question 45
Courses Beating the College Average
Courses Beating the College Average
In a CTE namedcourse_avg, compute each course's average grade (course_idandavg_grade, rounded to 2 places) over the enrollments that have a grade. Join it tocoursesand returncode,titleandavg_gradefor the courses whose average is above the average of every graded enrollment taken together: oneAVG(grade)over the wholeenrollmentstable (a scalar subquery or a second CTE), not an average of the course averages. Sort byavg_gradedescending.
Expected result:
+---------+-----------------------------+-----------+ | code | title | avg_grade | +---------+-----------------------------+-----------+ | MATH220 | Linear Algebra | 95 | | ENG101 | Academic Writing | 81.6 | | CS310 | Operating Systems | 79 | | CS101 | Introduction to Programming | 77.56 | +---------+-----------------------------+-----------+ 4 rows
Hints3 available
Sign in to use hintsTopics:
CTEs
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.