模糊查询:本质是比较运算符
| 运算符 | 语法 | 描述 |
| is null |
a is null |
如果操作符为null,则结果为真 |
| is not null |
a is not null |
如果操作符不为null,则结果为真 |
| between |
a between b and c |
若a在b和c之间,则结果为真 |
| like |
a like b |
SQL匹配,如果a匹配到b,则结果为真 |
| in |
a in(a1,a2,a3...) |
假设a在a1、a2、a3...其中的某一个值中,结果为真 |
-- ============================模糊查询====================================
-- like结合 % 或 _
-- % : 代表0到任意个字符
-- _ : 代表一个字符
-- 查询姓张的同学
select studentno,studentname from student where studentname like '张%';
-- 查询姓张的同学,名字后面只有一个字的
select studentno,studentname from student where studentname like '张_';
-- 查询姓张的同学,名字后面只有俩个字的
select studentno,studentname from student where studentname like '张__';
-- 查询名字中间带五的同学
where studentname like '%五%';
-- ============================in====================================
-- 查询 1001、1002、1003号学员
select studentno,studentname from student where studentno in (1001,1002,1003);
-- 查询在北京的学生
-- select studentno,studentname from student where address in ('北京%'); in是具体的值,模糊查询只能和like使用
select studentno ,studentname from student where address in ('福建福州','北京朝阳');
-- ============================null \ not null===================================
-- 查询地址为空的学生 null ''
select studentno ,studentname from student where address = '' or address is null;
-- 查询有邮箱的同学 不为空
select studentno ,studentname,email from student where email is not null;
-- 查询没有邮箱的同学 为空
select studentno ,studentname,email from student where email is null;