在为我所在的学校做项目时,我需要在mySQL查询中执行一些IF类型的语句。如果他们是HS学生,他们就会提交此表格。
因此,例如,我希望能够检查是否已根据人员等级向学校发送了多个表格,并回来时所有学生都缺少某种形式
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)
这不是一种或两种类型或条件,如果这个人在高中(等级等级9),则更多,检查他们是否也提交了这份表格。
非常感谢任何帮助
答案 0 :(得分: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
... ... ...