条件查询

条件查询

什么是条件查询?

不是将表中所有数据都查出来,是查询出来符合条件的

语法格式:
	select
		字段1,字段2,字段3...
	from
		表名
	where
		条件;
		
SELECT name from sarl where money >= 500; // 从sarl表里查询名字 条件时工资大于等于500


select money from sarl where name = '张三'; // 也可以使用字符串

between ... and ...两个值之间,等同于>= and <=;

第一种方式:>= and <=;
select name from sarl where money >= 4000 and money <= 6000;

第二种方式:between...and...
select
	name,money
from
	sarl
where 
 	money between 4000 and 6000;

注意:使用between and的时候,必须遵循左小右大
between and是闭区间,包括两端的值

查询补贴为空的人
image

注意:在数据库当中null不能使用等号进行衡量,需要使用is null,因为数据库中的null代表什么也没有,他不是一个值,所以不能用等号衡量

查看不为null的工资
image

and并且

image

or或者
image

and 和 or 同时出现
image
同时出现and优先级较高,如果想要or先执行,需要加小括号

in 包含,相当于多个or

image

注意:in不是一个区间,in后面跟的是具体的值

查询年龄是15和18的学生信息
image

not 可以取反,主要用在is或in中
is null;
is not null;
in();
not in();

like
称为模糊查询,支持%或下划线匹配
%匹配任意多个字符
下划线:任意一个字符

image

posted @ 2021-09-12 23:19  guided  阅读(359)  评论(0)    收藏  举报