在为学校做一个项目时,我需要在mySQL Query中做一些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)
它不是一个或一个类型或条件,如果该人正在读高中(gradelevelId 9),则更多,请查看他们是否也提交了此表格。
任何帮助将不胜感激
最佳答案
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
... ... ...
关于mysql - mySQL IF语句,如何匹配值并添加多个条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19663836/