我正在研究过滤器搜索,我可以组成一个查询,但它的 AND 部分没有返回正确的值,它为 gpa 返回正确的结果,但它没有为学位检查提供正确的结果,因为它返回所有记录不适用这里的“BSCS”过滤器是查询代码:
SELECT *
FROM education
WHERE gpa >= 2.10
OR gpa =0
AND degree = 'BSCS'
OR degree = NULL
看起来您需要添加一些括号:
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 = '')
)
试试下面的代码:
使用 And/OR 条件时,请务必加上括号以避免混淆。检查字段是否为空的最佳方法是WHERE myField IS NULL
SELECT *
FROM education
WHERE (gpa >= 2.10 OR gpa =0 )
AND (degree = 'BSCS' OR degree is NULL)