如何显示与类别关联的项目数

I have 2 tables for students and courses. The first contains student names who are each in a course and the second contains the courses and each course has a checkbox associated with it.

My question is, how do I display the number of students that are in a each course that is checked?

Example:

  1. There are three students names named Anna, Mia, and John
  2. There are two courses: IT and Engineering
  3. Anna and Mia are in IT and John in Engineering
  4. If the "IT" is checked, it should display 2 students (Anna and Mia)
  5. If both "IT" and "Engineering" are both checked it should display total number of students in all checked courses (3 students . . . Anna, Mia, and John)

I am new to programming, so I appreciate any help you can give me. :D

select c.*, count(sc.student_id) as total
from students_courses sc
left join courses c on c.id = sc.course_id
group by c.id

Here I assume that you have 3 tables.

courses (id, name, status)
students(id, name, email, ...)
students_courses (id, course_id, student_id)