🌟博主主页:我是一只海绵派大星

(图片来源网络,侵删)
📚专栏分类:软件测试笔记

(图片来源网络,侵删)
一、字段的别名
二、表的别名
三、distinct过滤重复记录
四、where子句
五、select查询的基本规律
六、比较运算符
七、逻辑运算符
1、and(与)
2、or(或)
3、not(非)
八、模糊查询
九、范围查找
一、字段的别名
- 通过 字段名 as 别名 的语法,可以给字段起一个别名,别名可以是中文
- as可以省略
- 字段名 as 别名 和 字段名 别名 结果是一样的
//通过as 给字段起一个别名 select card as 身份证, name as 姓名,sex as 性别 from students; //别名的as可以省略 select card 身份证, name 姓名,sex 性别 from students;
二、表的别名
- 通过 表名 as 别名 给表起一个别名
- as可以省略
//通过as 给表students起一个别名 select * from students as stu; //可以省略as select * from students stu;
三、distinct过滤重复记录
通过 select distinct 字段名 , 字段名 from 表名 来过滤 select 查询结果中的重复记录SELECT DISTINCT sex, class from students;
四、where子句
- where 后面跟一个条件,实现有选择的查询
- select * from 表名 where 条件
//查询 students 表中学号 studentNo 等于’001’ 的记录 ect * from students where studentNo = '001'; //查询 students 表中年龄 age 等于 30 的姓名 name,班级 class select name, class from students where age = 30;
五、select查询的基本规律
- select * 或者select 字段名 控制了查询返回什么样的字段(列)
- where 条件 控制了查询返回什么样的记录(行)
- where 后面支持多种运算符,进行条件的处理
- 比较运算
- 逻辑运算
- 模糊查询
- 范围查询
- 空判断
六、比较运算符
- =等于
- 大于
- >= 大于等于
- !=和不等于
//查询 students 表中 name(姓名)等于’小乔’学生的 age(年龄) select age from students where name = '小乔'; //查询 students 表中 30 岁以下的学生记录 SELECT * from students where age