In my database a Teacher has a TeacherPIN, Name and Pay. My database also has a Class which contains a ClassPIN as well as a TeacherPIN and Student that has a reference to TeacherPIN as well as several ClassPINs. I want to update a certain teacher's pay based on if they have more than 25 students in a certain class, but am stuck. Currently I'm doing:
update Teacher
set Pay = Pay + 1000
where (TeacherPIN = c.TeacherPIN from Class c
and c.ClassPIN = '1010')
and (select count(s.ClassPIN) from Student s
where s.ClassPIN = '1010') >= 25;
I know this is probably very wrong and would love a nudge in the right direction.