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 trialMuhittin Palamutçu
1,890 PointsI need some help for my Sql Query
Student(id(key),name) Professor(id,name,deperment) Course(number(key),instructorID,title,credits,roomNumber) Enroll(StudentID(key),courseNumber(key) Room(number(key),capacity)
I need to find course number and their titles that have more than 40 students enrolled?
SELECT C.number,C.titles FROM Course C,Enroll E WHERE C.number=E.courseNumber AND E.count(StudentID)>40;
I wrote something like that but ı know it's false. If you help me ı will be pleased.
2 Answers
KRIS NIKOLAISEN
54,971 PointsTry this:
SELECT enroll.courseNumber, course.title FROM course, enroll WHERE course.number = enroll.courseNumber GROUP BY enroll.courseNumber, course.title HAVING ( ( COUNT( enroll.studentID ) > 40 ) )
Steven Parker
231,248 PointsIt looks like you're getting close, here's a couple of hints:
- a GROUP BY might be handy when counting things that have something in common
- another way to filter when using grouping is with the HAVING keyword