CrapCoder
CrapCoder

Reputation: 11

SQL problem: 3 tables, requiring JOIN, COUNT, GROUP BY

I have three (3) tables: Course, Student, Registration. The columns in each table are:

I'm having a hard time figuring out how to write the correct statement that will list the course numbers and titles of courses that have more than 10 students getting a grade lower than 50. I'd like to be able to GROUP BY CourseNo and have a COUNT based on SID.

Any help would be much appreciated, especially if any explanation can be given.

Thanks in advance!

Upvotes: 0

Views: 172

Answers (1)

ahmet_y
ahmet_y

Reputation: 112

I hope this help

select c.CourseNo, c.Title, count(SID) AS sCount
  from Registration r
  join Course c on (c.CourseNo = r.CourseNo)
  where r.Grade < 50
  group by r.CourseNo
  HAVING sCount > 10;

Upvotes: 2

Related Questions