sqlserver中or和and优先级问题

今天发现写的接口有问题,排查到最后发现因为自己忽略了sqlserver中or和and的优先级,导致查询的数据不正确。

关于他们的使用见下面的例子

比如想要查询高三2班2000年出生或者是2002年出生的所有男生,那么sql应该这么写

1
select * from tb_class where sex = 'male' and (birth = '2000' or birth = '2002')

还有另一种写法,可以用in代替or

1
select * from tb_class where sex = 'male' and birth in ( '2000' , '2002')

sqlserver中or和and优先级问题
http://example.com/2018/07/27/2018-07-27-sqlserver-sqlserver中or和and优先级问题/
Author
Hoey
Posted on
July 27, 2018
Licensed under