是
本章查询方式有合并列查询、比较条件查询、逻辑条件查询、判空条件查询
演示的表中的内容:
一 、合并列查询:适用于多条件查询,比如学生的班级、姓名一起查询
-- 查询 合并列查询 关键字CONCAT(字段名,字段名)
命令:select CONCAT(id,name) ' from student1;
返回结果如下,看着比较难看id name挤在一起,所以可以使用别名的方式美化一下
命令:select CONCAT(id,name) '编号-姓名' from student1;
返回结果:
美化前 美化后的
二、比较查询
1、大于小于查询的方式,这里查询一下id号大于8的有哪些?
命令: select * from 表名 where id > 8;
试列:select * from student1 where id > 8;
返回结果:
2、范围比较查询,关键字between and。只查询在该范围内的数据
命令 select * from 表名 where字段名 between 6 and 8;
试列:select * from student1 where id between 6 and 8;
返回结果:只显示了6、7、8,在范围内
三、逻辑查询
逻辑查询包括两个内容 and与or,and是和与且的意思,两个条件同时满足才能查询成功,or就是或的意思,两个条件满足一个就能查询。
这里用and做演示
命令: select * from 表名 where 字段名 = 字段值 and 字段名 < 字段值;
提示这里的”<“可以换成=> 都可以满足逻辑就行
实列:select * from student1 where name = '撒旦' and id < 8;
返回结果:只能查询到同时满足name为撒旦,id小于8的值。
四、判空查询(判断是否为空的意思)
判断空值查询有 = 与!=,判断null值有is null 与is not null
#因为创建表的时候没有添加空值和NULL,所以就在这里直接创建几个
insert into student1 (name) values (null); #因为表没有空和null所以先建
insert into student1 (name) values ('');
insert into student1 (sex1) values (null);
insert into student1 (sex1) values ('');
判空条件查询命令:
select *from 表名 where 字段名 != ''; #查询空值有 = 和!=s
select *from 表名 where 字段名 is null; #查询null有is null 和is not null
select *from 表名 where 字段名 != '';
拓展: 可以使用逻辑条件一起使用
select *from 表名 where 字段名 is not null and 字段名 !='';
返回结果name中的空值与null值都没有了
新人出击!