转自https://blog.csdn.net/a781568222/article/details/68927129,感谢作者的无私分享。
where子句中的运算符:
<,>,=,!=,>=,<=,in(),between...and...,and,not,or,like,is null,is not null,<=>(安全等于)
1、其中 <,>,=,!=(<>),>=,<=,in(),between and 属于比较运算符
in(A,B):表示包含A和B的结果
between 1 and 5 :会查出在1和5之间的值包括1和5
2、and,not,or属于逻辑运算符
select * from user where age>4 and age <14 : 查询的出来的结果集中的age处于4和14之间,不包括4和14
select * from user where age>4 or age <3 : 查询的出来的结果集中的age有大于4的也有小于3的,不包括4和3
select * from user where not age>4 :查询的出来的结果集中的age没有大于4,可以等于4
3、、like是模糊查询
select * from user where phone like '130%' 查询出user表中phone为130开头的用户
select * from user where phone like '130_' 查询出user表中phone为130开头后面只有一位的用户,比如1301
select * from user where phone like '%130%' 查询出user表中phone中含有130的用户
select * from user where phone like '%130'查询出user表中phone为130结尾的用户
select * from user where phone is null 查询没有写电话号码的用户的信息
%为通配符,不限定位数
_也是通配符,一个表示一位
<=>(安全等于)的介绍
既可以判断是否等于null值,也可以判断是否等于某个普通数值(但是不推荐使用,因为可读性比较差)。