以下查询无需添加额外的"OR"
参数即可正常运行。
SC和CC的查询结果由于某种原因没有格式化为WHERE
子句,并且在我的参数之外返回了几个日期。我应该如何更改此语法以确保我的WHERE
子句影响OR
语句?
SELECT DISTINCT case_number, case_filed_date
FROM [case]
WHERE case_filed_date BETWEEN '2012/07/01' AND '2012/09/30'
AND case_number LIKE '%CA%' OR case_number LIKE '%SC%' OR case_number LIKE '%CC%'
答案 0 :(得分:1)
添加括号
SELECT DISTINCT case_number, case_filed_date
FROM [case]
WHERE case_filed_date BETWEEN '2012/07/01' AND '2012/09/30'
AND
(
case_number LIKE '%CA%' OR case_number LIKE '%SC%' OR case_number LIKE '%CC%'
)
and
强于or
答案 1 :(得分:1)
使用括号尝试此操作,因为AND
的优先级高于OR
: -
SELECT DISTINCT case_number, case_filed_date
FROM [case]
WHERE case_filed_date BETWEEN '2012/07/01' AND '2012/09/30'
AND
(case_number LIKE '%CA%' OR case_number LIKE '%SC%' OR case_number LIKE '%CC%')