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!
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!
您可以按 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;