单表查询
1. 指定查询
-- 查询1001信息?
select * from user where 1001
2. 带in关键字查询
-- 查询1001、1004、1009 三个人信息?
select * from user where id = 1001 or id = 1004 or id = 1009;
3. Between And 两者之间【包含两端的值】
-- 查询成绩在73 ~82之前的学生的姓名
select name from user where grade >=73 and grade <=82;
select name from user where grade between 73 and 82;[推荐]
4. not Between And 不在两者之间
-- 查询编号不在1008~1016 之间的学生的姓名
select name from user where id <1008 and id >1016;
select name from user where id not between 1008 and 1016; [推荐]
5. 空值查询
-- 查询user表中成绩为空的用户信息?
select * from user where grade is null;
6. 不为空值查询
-- 查询user表中成绩不为空的用户信息?
select * from user where grade is not null;
7. 去重复查询[distinct] distinct 必须紧跟着select
-- 查询user表中的用户,去除重复name
select distinct name from user;
8. 模糊查询 - like
-- 查询user表中姓名的开头姓周?
select * from user where name like "周%";
- % 百分号 : 通配符
-
- 含义: 可以代替 任意长度、任意内容。
- _下划线: 占位符
-
- 含义:可以代替任意内容,一个(下划线代表一个)长度
-- 查询user表中姓名中含有星字?
select * from user where name like "%星%";
-- 查询user表中姓名中以范字开头、冰字结束?
select * from user where name like "范%冰";
-- 查询user表中姓名有三个字,末尾是华?
select * from user where name like "__华";
-- 查询user表中姓名有%的用户?
select * from user where name like "%\%%"; -- | 反转字符