假设我有这个声明:
SELECT * FROM MyTable WHERE a = 1 or b = 2 and c = 3
这是否意味着:(a = 1) OR (b = 2 AND c = 3) 还是意味着 (a = 1 or b = 2) AND c = 3?我可以更改它的含义,即在 AND 之前执行 OR,或者这不可能吗?
假设我有这个声明:
SELECT * FROM MyTable WHERE a = 1 or b = 2 and c = 3
这是否意味着:(a = 1) OR (b = 2 AND c = 3) 还是意味着 (a = 1 or b = 2) AND c = 3?我可以更改它的含义,即在 AND 之前执行 OR,或者这不可能吗?
来自技术网:
当一个语句中使用多个逻辑运算符时,首先计算 AND 运算符。您可以使用括号更改评估顺序。
所以是的,这意味着(a = 1) OR (b = 2 AND c = 3)
。
您可以通过像上面那样编写括号来强制执行您想要的行为:(a = 1 OR b = 2) AND c = 3