SQL得逻辑
SQL中 OR条件左右只要有一个成立,就可以返回true结果,所以在和and使用得时候 ,OR必须要加上括号来使用。
SELECT * FROM actor WHERE actor_id > 10 AND (first_name LIKE '%A%' OR last_name LIKE '%A%');
SELECT * FROM actor WHERE actor_id > 10 AND first_name LIKE '%A%' OR last_name LIKE '%A%';
也因此在Mybatis-Plus 中QueryWrapper组装中,也要注意这种情况。
queryWrapper.and(Wrapper -> Wrapper.like("first_name", "mama").or().like("last_name ","mama"));
queryWrapper.ge("actor_id",10);
// 等同于 WHERE actor_id > 10 AND (first_name LIKE '%A%' OR last_name LIKE '%A%');
queryWrapper.like("first_name", "mama").or().like("last_name ","mama");
queryWrapper.ge("actor_id",10);
// 等同于 WHERE actor_id > 10 AND first_name LIKE '%A%' OR last_name LIKE '%A%'; 这种写法是错误得