-2

I have a table called teacher_student_course with teacher_id, student_id, and course_id how would I return a course_id for a course where the student count is lets say above 50?

please help my mind is shot its midnight!

4

1 回答 1

3

您可以按 course_id 进行分组,并获得所有具有 50 条以上记录的组。

SELECT course_id
FROM teacher_student_course
GROUP BY course_id
HAVING COUNT(*) > 50

如果您想检查一门课程是否有超过 50 名学生,您需要使用类似的查询,但需要使用 JOIN,如下所示。

SELECT tsc.course_id
FROM teacher_student_course tsc 
         INNER JOIN course ON course.id = tsc.course_id
WHERE course = 'course name'
GROUP BY tsc.course_id
HAVING COUNT(tsc.course_id)>50;

计数大于 4 的演示

于 2013-09-15T04:26:06.723 回答