我正在进行过滤器搜索,我可以组成一个查询,但它的AND部分没有返回正确的值,它的返回结果为gpa,但它没有给出正确的度数检查结果,因为它返回所有记录不适用“BSCS”过滤器这里是查询代码:
SELECT *
FROM education
WHERE gpa >= 2.10
OR gpa =0
AND degree = 'BSCS'
OR degree = NULL
答案 0 :(得分:7)
看起来您需要添加一些括号:
SELECT *
FROM education
WHERE (gpa >= 2.10 OR gpa =0)
AND (degree = 'BSCS' OR degree is NULL)
如果要扩展WHERE
子句,则可以使用:
SELECT *
FROM education
WHERE
(
(gpa >= 2.10 OR gpa =0)
AND (degree = 'BSCS' OR degree is NULL)
)
OR
(
(gpa is null or gpa ='')
or (degree is null or degree = '')
)
答案 1 :(得分:0)
尝试以下代码:
使用And / OR条件时始终加上括号以避免混淆。
另外,检查字段是否为空的最佳方法是WHERE myField IS NULL
SELECT *
FROM education
WHERE (gpa >= 2.10 OR gpa =0 )
AND (degree = 'BSCS' OR degree is NULL)