1.数字比较 & 字符比较 & 逻辑比较
数值:=,!=,>,>=,<,<=
字符:=,!=
逻辑:and or
2.范围内比较
between value1 and value2
in(value1,value2,...) 、 not in(value1,value2,...)
3.匹配空和非空
空:is null
非空:is not null
4.示例:
查找姓名为空的男英雄
select * from WANGZHE where name is null and sex='男';
查找姓名为""的英雄的id,姓名和国家
select id,name,country from WANGZHE where name="";
备注:
1. NULL:空值,必须用is或者is not去匹配
2. "":空字符串,只能用=或者!=去匹配
5.模糊比较
1)where 字段名 like 表达式
2)表达式:
_ : 匹配单个字符
% : 匹配0到多个字符
3)示例:
select * from WANGZHE where name like "_%_";
select * from WANGZHE where name like "%"; #不含NULL,NULL用is[is not]匹配
select * from WANGZHE where name like "___";
select * from WANGZHE where name like "赵%";
show tables like "%sa%";
show variables like "%character%";