and与or的优先级

写登录页面的时候一直不明白SQL注入攻击:1'or',是怎么回事后面and不用管了吗,后来发现是and与or一起使用会有一个优先级关系,and的优先级高于or,会先执行and在执行or,这样where 1就为真了,不用管密码就可以直接登陆了

例:查找分数大于80分的男生女生

     select * from  type_student where sex='男' or sex='女' and score>80;

     这样会先执行and,结果是不对的;

     应该在sex='男' or sex='女' 加上括号,如下:

     select * from  type_student where (sex='男' or sex='女' )and score>80;

猜你喜欢

转载自blog.csdn.net/study_no/article/details/79840473