I have a table students with student id, subjects and number of roles per subject. How to find students who studied at least two subjects where they had exactly three roles?
student subject num_roles
1000 223 2
1000 223 1
-------------------------------
1043 243 3
-------------------------------
1002 109 3
1002 230 3
1002 200 1 valid student
...
I can only think of finding students and their subjects that are equal to 3 num_roles. But how to modify the code to find students with 3 roles in at least 2 subjects?
SELECT s.student, s.subject
FROM students s
WHERE s.num_roles = 3
ORDER BY s.student, s.subject;
Expected output:
student subject
1002 109
1002 230
...