MySQL(入门篇08)模糊查询操作符号详解.

一、模糊查询操作符

1. null

查询 为 null 的 数据,通常和 “” 空字符串搭配使用
(1) 查询没有填家庭住址的同学

select `id` , `name` 
from student 
where (`homeAddress` is null or `homeAddress` = "");

2. is not null 上

3. between 在…之间

下面2个相等的
(1)查询90-100分的学生

select `id`,`name` 
from student
where ( `score` >= 90 and score <= 100);

(2)查询90-100分的学生

select `id`,`name` 
from student
where ( `score` between 90 and 100);

4.(重点)like 匹配

1.了解2中通配符
(1) (%) 百分号 匹配 0-n 个字符
(2) ( _ )下划线 ,匹配 一个字符

2.查询姓为 张 的同学

select `id`,`name` 
from student
where (`name` like "张%");

3.查询 姓名为张的名只有一个字同学

select `id`,`name` 
from student
where (`name` like "张_");

4.查询 姓名为张的 名只有2个字同学

select `id`,`name` 
from student
where (`name` like "张__");

5. (重点) in

1.公式 :a in(a1,a2,a3)
2.查询在城市在 北京 和 南京 的同学

select `id`,`name` 
from student
where (`homeAddress`in ("北京","南京"));

总结:

在这里插入图片描述

原创文章 132 获赞 11 访问量 4678

猜你喜欢

转载自blog.csdn.net/jarvan5/article/details/106176906