0

While doing a project for the school I work at I needed to do some IF type of statements in my mySQL Query. Things like if they are a HS student did they submit this form.

So for instance I would love to be able to check if multiple forms had been sent to the school based on a persons grade level and come back with all students missing some sort of form

SELECT studentId 

FROM students 

WHERE formBirthCertificate != 1 AND anotherForm != 1 and familyForm  != 1

IF (gradeLevelId >= 9 then formHighSchool  !=1)//they are High School student did they submit a form

IF  (gradeLevelId >= 5 then formStudent !=1)

It is not an either or type or condition, it is more if the person is in high school (gradelevelId 9), check to see they also submitted this form.

Any help would be greatly appreciated

4

1 回答 1

0
SELECT studentId, 
(case when gradeLevelId >= 9 then 0 ELSE 1 end) AS formHighSchool, 
(case gradeLevelId >= 5 then 0 ELSE 1 end) AS formStudent
FROM students 
WHERE formBirthCertificate != 1 AND anotherForm != 1 and familyForm  != 1

应该返回类似:

studentId   formHighSchool   formStudent
    1             0              1
    2             0              0
    3             1              0
    4             1              1
   ...           ...            ...
于 2013-10-29T16:41:58.553 回答