我有以下查询:
"SELECT COUNT(*) FROM Persons WHERE {1}='A' AND {2}!='A' AND {3}!='A'"
我有以下任务:从表格中获取所有条目,其中{1}为A而{2}或{3}不是'A',即ABC,ABA等。现在我只能获得ABC ,ABB等,而不是ABA。请帮我。
答案 0 :(得分:2)
使用括号赋予逻辑运算符优先级
"SELECT COUNT(*) FROM Persons WHERE {1}='A' AND ({2}!='A' OR {3}!='A')"
答案 1 :(得分:0)
逻辑方面的简化,将{2}和{3}进行比较?
SELECT COUNT(*)
FROM Persons
WHERE {1}='A' AND {2}+{3} != 'AA'
如果没有括号,您可以查看Operator Precedence
SELECT COUNT(*)
FROM Persons
WHERE {1}='A' AND {2}!='A'
OR {1}='A' AND {3}!='A'