Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Much better way to write the code for MOST POPULAR ELECTIVE TEACHER

-- Which elective teacher is the most popular (teaches the most students)?

WITH STUDENTS_TAUGHT_BY_ELECTIVE_TEACHERS AS ( SELECT TEACHERS.FIRST_NAME, TEACHERS.LAST_NAME, COUNT(*)"CT" FROM TEACHERS JOIN CLASSES ON CLASSES.TEACHER_ID = TEACHERS.ID JOIN SCHEDULE ON SCHEDULE.CLASS_ID = CLASSES.ID JOIN STUDENTS ON STUDENTS.ID = SCHEDULE.STUDENT_ID JOIN SUBJECTS ON SUBJECTS.ID = CLASSES.SUBJECT_ID WHERE SUBJECTS.GRADE IS NULL GROUP BY TEACHERS.FIRST_NAME ) SELECT FIRST_NAME, LAST_NAME, MAX(CT) FROM STUDENTS_TAUGHT_BY_ELECTIVE_TEACHERS

1 Answer

Steven Parker
Steven Parker
229,644 Points

Better than what (what are you comparing this to)?