Is it possible to perform a count based on a combination of two columns?
I have 3 tables:
student:
Student id | Student name | Gender | Dob |
class register: Student id | Class id
Both columns make up the composite primary key.
Classes: Class id | Class name | Class day
I would like to perform a count of the number of students of each gender in each class.
I came up with this query so far:
SELECT class_name AS 'class Name',
Child_gender AS 'Gender',
COUNT(student_id) AS 'Count'
FROM student,classRegister,classes
WHERE student.student_id=classRegister.student_id AND
classRegister.class_id=classes.class_id
GROUP BY class_name,student_gender
ORDER BY class_name;
But it seems to be giving me duplicate results for some of the students.
So, can I modify this query to count the number of instances of a combination of the student_id and class_id?
I’m still very new to MySQL, so I apologise if this is basic for everyone
Try this: