MySQL学习笔记---DQL(条件查询,模糊查询)

一:条件查询

1:where子句后跟条件

2:运算符

  *  >、<、<=、>=、=、<>(不等于)

  * BETWEEN.......AND

  *IN(集合)

  *LIKE

    占位符:"_"表示单个任意字符

        "%"表示任意多个字符

  *IS NULL

  *and 或 &&(与操作)

  *or 或 ||(或操作)

  *not 或 !

接下来我们依旧以学生表来查询

  

 

 

 --查询年龄大于(大于等于)20岁的人的基本信息

  select * from student where age>20;

  select * from student where age>=20;

--查询年龄大于(大于等于)20岁的人的基本信息

  select * from student where age<20;

  select * from student where age<=20;

--查询年龄大于(大于等于)20岁的人的基本信息

  select * from student where age!=20;

  select * from student where age<>20;

--查询年龄大于等于20小于等于30岁的人的基本信息

  select * from student where age>=20 and age<=30

  select * from student where age between 20 and 30

--查询年龄22岁,19岁,25岁的信息

  select * from student where age IN(22,18,25)

  

 

 --查询英文成绩为null(注意,null值不能使用=或者!=判断

  select * from student where english is(not) null

 

 

二:模糊查询(LIKE)

  --查询班级里面姓马的有哪些

    select * from student where name like '马%'

    

 

   --查询第二个字是化的人

    select * from student where name like '_化%';

    

 

  --查询姓名是三个字的人

    select * from student where name like '___'(三个杠)

    

 

 

  --查询姓名中包含马的人

    select * from student where name like '%马%'

    

 

posted @ 2020-04-26 15:10  一天一天yg  阅读(181)  评论(0编辑  收藏  举报