一、基本概念:
1、定义:数据库是按照数据类型分类存储数据的仓库
2、数据裤在测试中的作用:加深了测试的深度。
Create database 库名 创建数据库
Drop database 库名 直接删除数据库,不再提醒
Show databases 查询数据库
Use database 库名 进入数据库
Create tables 表名 创建表
Drop table 表名 删除表
Show tables 查询表
Describe table 表名 查询表结构
Select distinct name from student
二、单表查询:
1、查询学生表,查询学生“张三”的全部基本信息
Select * from xsb
Where xm=’张三’;
2、 查询学生信息表,查询学生‘张三’和‘李四’的基本信息。
Select * from xsb
From xm=’张三’ or’李四’;
3、 查询学生表,查询年龄大于20岁,且是1班学生的基本信息。
Select * from xsb
Where nl>20 and bj=’1班’;
4、 查询张三或李四且年龄大于20岁的学生的基本信息。
Select * from xsb
Where xm=’张三’or’xm=’李四’and nl>20;
5、 查询姓张同学的姓名、年龄、班级。
Select * from xsb
Where xm like ‘张%’(not like);
6、 查询姓名中含有四个字的学生基本信息
Select * from xsb
Where. Xm like ‘%四%’;
7、 查询姓名长度为三个字,姓‘李’,最后一个字是‘龙’的全部学生的全部信息。
Select * from xsb
Where xm. Like ‘李_龙’;
8、 查询姓‘张’或者姓“李”的学生的基本信息
Select * from xsb
Where. Xm like ‘张%’ or xm like ‘李%’;
9、 查询姓“张”并且所属省份是“北京”的学生信息。
Select * from xsb
Where xm like ‘张%’ and jg =’北京’;
10、 查询所属身份是“北京”、“新疆”、“山东”或者“上海”的学生信息。
Select * from xsb
Where jg in(‘北京’,‘新疆’,‘山东’,‘上海’);
11、查询姓“张”,但是“所属省份”不是“北京”的学生信息。
Select * from xsb
Where xm like “张%”and jg<>’北京’;
12、查询不是姓“张”,且所属省份是“河北”的学生信息。
Select * from xsb
Where xm no like ‘张%’and jg=’河北’;
13、查询成绩在80-95之间的学生的学号和成绩。
Select * from cjb
Where cj between 80 and 95;
14、给字段起个别名,不改变数据中的字段
Select xh as ‘学号’from cjb
Where cj between 80 and 95;
15、查询成绩在80-95之间的学生的学号、课程号、成绩并排序。
Select * from cjb
Where cj between 80 and 95
Order by cj asc(desc);
16、查询学生来自不同的省份,去掉重复的
Select distinct jg
From xsb;
内链接:
1、 查询张三的课程成绩,并显示学号、姓名、课程号和成绩
Select xsb.xh.xm.kch.cj from xsb inner join cjb
On xsb.xh = cjb.xh
Where xm=’张三’;
左链接:
2、 查询所有学生的课程成绩,并显示学号、姓名、课程号和成绩,包括没有选择课程的学生。
Select * from xsb left join cjb
On xsb.xh = cjb.xh;
右链接:
3、 查询所有学生的课程成绩,并显示学号、姓名、课程号和成绩,包括没有选择课程的学生。
Select * from xsb right join cjb
On xsb.xh=cjb.xh
增加:
Insert into、、、values
改:Update 表名
Set
Where