and的优先级大于or
如:
①select * from tablename where condition1 or condition2 and condition3
其实相当于
select * from tablename where condition1 or (condition2 and condition3)
②select * from tablename where condition1 and condition 2 or condition3 and condition4
其实相当于
select * from tablename where
(condition1 and condition 2) or
(condition3 and condition4)
注意:
在不确定执行顺序的时候,最好加上括号,括号的优先级最高,可读性也强
本文解析了SQL中and与or运算符的优先级规则,并通过具体示例展示了如何正确使用这些运算符来确保查询结果的准确性。为提高SQL语句的可读性和避免误解,文章还强调了适当使用括号的重要性。
1523

被折叠的 条评论
为什么被折叠?



