Reputation: 77
Im making a system for a school and I have this mySQL tables. The names are self explanatory:
student: id name course_id
course: id name
subject: id name
subject_course: id subject_id course_id
grade: id type grade
grade_type: id name
I need to check if every student of a certain course has a grade of type X on every subject that is related with that course. Let's say grade_type = 'written test'. So I need to check if every student of 1st grade has a grade on the written test on EVERY subject related to first grade (example: math, spanish, history, etc). If yes, I do some stuff. If not, another.
Is there a query that can check that? I was thinking on check student by student but I think is less efficient.
Upvotes: 0
Views: 43
Reputation: 71422
This schema doesn't seem to make sense.
Why would course_id be field on student table? My guess is you need a student_course
table to represent a many-to-many relationship between students and courses here.
Also, the grade_type
table seems kind of trivial and extra overhead with little value. Could type
not just be an enum on grade
table?
Upvotes: 1