1. 不是将表中所有数据都查出来,是查询出来符合条件的
  2. 语法格式:
  3. select
  4. 字段1,字段2,字段3...
  5. from
  6. 表名
  7. where
  8. 条件;
  9. SELECT name from sarl where money >= 500; // 从sarl表里查询名字 条件时工资大于等于500
  10. select money from sarl where name = '张三'; // 也可以使用字符串
  11. between ... and ...两个值之间,等同于>= and <=;
  12. 第一种方式:>= and <=;
  13. select name from sarl where money >= 4000 and money <= 6000;
  14. 第二种方式:between...and...
  15. select
  16. name,money
  17. from
  18. sarl
  19. where
  20. money between 4000 and 6000;

注意:使用between and的时候,必须遵循左小右大

between and是闭区间,包括两端的值

查询补贴为空的人
image.png

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

查看不为null的工资

image.png

and并且
image.png

or或者
image.png

and 和 or 同时出现
image.png

同时出现and优先级较高,如果想要or先执行,需要加小括号
in 包含,相当于多个or
image.png

注意:in不是一个区间,in后面跟的是具体的值
查询年龄是15和18的学生信息
image.png

not 可以取反,主要用在is或in中
is null;
is not null;
in();
not in();
like
称为模糊查询,支持%或下划线匹配
%匹配任意多个字符
下划线:任意一个字符
image.png

排序

默认是升序
image.png
怎么降序?
指定降序
image.png
指定升序
image.png

多个字段排序

按照id号升序,如果id一样再按照名字升序
image.png
根据字段位置也可以排序
image.png
综合
image.png