有关数据表的DML操作
- INSERT 针对于数据的插入
- DELETE 针对于数据的删除
- UPDATE 针对于数据的修改
4.1 INSERT语句
INSERT INTO 表名 [(列名1,列名2,....)] VALUES (值1,值2,...);
默认情况下,一条插入命令只针对一行进行影响
INSERT INTO 表名 [(columnName,[columnName...])] VALUES (value[,value....]),(value[,value....]),(value[,value....]).....;
一次性插入多条记录
PS 如果我们为每一列都要指定注入的值,那么表名后面就不需要罗列插入的列名了
INSERT INTO 表名 VALUES (值1,值2,值3,....)
CREATE TABLE `grade` (
`GradeID` int(0) NOT NULL AUTO_INCREMENT COMMENT '年级编号',
`GradeName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '年级名称',
PRIMARY KEY (`GradeID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
4.2 REPLACE语句
replace语句的语法格式有三种语法格式。
语法格式1:
replace into 表名 [(字段列表)] values (值列表);
语法格式2:
replace [into] 目标表名[(字段列表1) select (字段列表2) from 源表 [where 条件表达式];
语法格式3:
replace [into] 表名 set 字段1=值1, 字段2=值2;
REPLACE与INSERT语句区别:
replace语句的功能与insert语句的功能基本相同,不同之处在于:使用replace语句向表插入新记录时,如果新记录的主键值或者唯一性约束的字段值与已有记录相同,则已有记录先被删除(注意:已有记录删除时也不能违背外键约束条件),然后再插入新记录。
使用replace的最大好处就是可以将delete和insert合二为一(效果相当于更新),形成一个原子操作,这样就无需将delete操作与insert操作置于事务中了
4.3 DELETE语句 || TRUNCATE语句
DELETE (TRUNCATE) FROM 表名 [WHERE 条件];
DELETE:删除数据,保留表结构,必要时可以回滚,但是如果数据量较大,运行速度不及TRUNCATE。
TRUNCATE:删除所有数据,保留表结构,不能够回滚。一次全部删除所有数据,速度相对很快。
DROP:删除数据和表结构,删除速度最快。
4.4 UPDATE数据
UPDATE 表名 SET 列名 = 值 [,列名 = 值,列名 = 值,列名 = 值,...] [WHERE 条件];
4.5 SELECT 语句(DQL数据查询语言)
基础语法
SELECT {*,列名,函数}
FROM 表名
[WHERE 条件];
说明:
-SELECT检索关键字 *匹配所有列 , 匹配指定列
-FROM 所提供的数据源(表,视图,另一个查询机制反馈的结果)
-WHERE 条件(控制查询的区域)
SELECT *
FROM student; #查询学生表的所有列以及所有行 ====> 学生表的全部信息
SELECT StudentName,Address,Email #查询指定三列的内容所有行 ====> 学生表的姓名 住址 邮箱
FROM student;
SELECT StudentName,Address,Email #查询指定三列的内容指定行 ====> 学生表的姓名 住址 邮箱
FROM student
WHERE sex = 0;
#结论 SELECT 关键字 和 FROM 关键字之间 写的东西 控制的是我们结果的列数
# WHERE 写的东西 控制的是我们结果的行数
#生日在2000-01-01 2010-01-01 的男生 的 姓名
SELECT StudentName
FROM student
WHERE BornDate>'2000-01-01' AND BornDate<'2010-01-01' AND sex = 1;
SELECT 语句中的算数表达式
对数值型数据列、变量、常量可以使用算数操作符创建表达式(+ - * /)
对日期型数据列、变量、常量可以使用部分算数操作符创建表达式(+ -)
运算符不仅可以在列和常量之间进行运算,也可以在多列之间进行运算。
SELECT 100+80;
SELECT '300'+80; #只要其中一个是数值类型,而另一个能够转成数值,则自动转换并计算
SELECT 'ABC'+20; #若转换不成功,则将其认为是数字0对待
SELECT 'Hello'+'World'; #若转换不成功,则将其认为是数字0对待
SELECT NULL+80; #只要有一个为NULL,则结果为NULL
运算符优先级
乘除优先级高于加减
同级运算时运算顺序由左到右
表达式内使用括号,可以改变优先级的运算顺序
SELECT *
FROM subject;
+-----------+-------------------+-----------+---------+
| SubjectNo | SubjectName | ClassHour | GradeID |
+-----------+-------------------+-----------+---------+
| 1 | 高等数学-1 | 110 | 1 |
| 2 | 高等数学-2 | 110 | 2 |
| 3 | 高等数学-3 | 100 | 3 |
| 4 | 高等数学-4 | 130 | 4 |
| 5 | C语言-1 | 110 | 1 |
| 6 | C语言-2 | 110 | 2 |
| 7 | C语言-3 | 100 | 3 |
| 8 | C语言-4 | 130 | 4 |
| 9 | JAVA第一学年 | 110 | 1 |
| 10 | JAVA第二学年 | 110 | 2 |
| 11 | JAVA第三学年 | 100 | 3 |
| 12 | JAVA第四学年 | 130 | 4 |
| 13 | 数据库结构-1 | 110 | 1 |
| 14 | 数据库结构-2 | 110 | 2 |
| 15 | 数据库结构-3 | 100 | 3 |
| 16 | 数据库结构-4 | 130 | 4 |
| 17 | C#基础 | 130 | 1 |
+-----------+-------------------+-----------+---------+
SELECT SubjectName,ClassHour,ClassHour*10+10
FROM subject;
SELECT SubjectName,ClassHour,ClassHour*(10+10)
FROM subject;
NULL值的使用
String str = null;
String str = "";
null指的是 不可用、未分配的值
null不等于零或空格
任意数据类型都支持null这种表达形式
包括null的任何算数表达式结果都等于空
字符串和null进行连接运算,结果也是空
补充点
<==> 安全等于 等价于 = 和 IS 两者的结合
示例1:查询学号为1001的学生信息
SELECT *
FROM student
WHERE StudentNo <==> 1001; # WHERE StudentNo = 1001;
示例2:查询邮箱为空的学生的信息
SELECT *
FROM student
WHERE Email <==> NULL; # WHERE Email IS NULL;
定义字段的别名
SELECT StudentName,Address,Email
FROM student;
+--------------+------------------------------------+--------------------+
| StudentName | Address | Email |
+--------------+------------------------------------+--------------------+
| 郭靖 | 北京海淀区中关村大街1号 | test1@bdqn.cn |
| 李文才 | 广东广州天河区 | test1@bdqn.cn |
| 李斯文 | 天津市和平区 | test1@bdqn.cn |
| 武松 | 上海市金桥区 | test1@bdqn.cn |
| 张三 | 北京市通州 | test1@bdqn.cn |
| 张秋丽 | 广西桂林市灵川 | test1@bdqn.cn |
| 欧阳峻峰 | 北京东城区 | NULL |
| 梅超风 | 河南洛阳 | NULL |
| 赵敏 | 西安市雁塔区 | NULL |
| 李寻欢 | 西安市碑林区 | litian@qq.com |
| 赵尧林 | 西安市雁塔区新家坡3号楼 | zhaoyaolin@163.com |
+--------------+------------------------------------+--------------------+
#查询语句获取到的结果 是以伪表形式体现
SELECT StudentName AS '学生姓名',Address AS '家庭住址',Email AS '电子邮箱'
FROM student;
SELECT SubjectName "科目名",ClassHour "学习时长",ClassHour*(10+10) "计算后的学习时长"
FROM subject;
祛除重复的记录
#我想查看学生表的性别
#缺省情况下查询显示所有行,包括重复行
SELECT sex "性别"
FROM student;
#可以使用关键字DISTINCT清除查询记录中的重复数据
SELECT DISTINCT sex "性别"
FROM student;
WHERE 限制所选择的横向区域
WHERE中的字符串或日期格式的内容
需要使用单引号进行专门的标识 如 StudentName = '张三' 而不能 直接 StudentName = 张三
字符串内的数据 对大小写是敏感的 如记录中有 Louis77@163.com 我们在检索时就不能 louis77@163.com
日期值对格式是敏感的 如记录中有 2000-01-01 00:00:00 我们在检索时就不能 2000年01月01日
#示例1:查询姓名是郭靖的学生信息
SELECT *
FROM student
WHERE StudentName = '郭靖';
#示例2:查询生日是1986-12-31的学生信息
SELECT *
FROM student
WHERE BornDate = '1986-12-31';
#示例3:查询学号是1000的学生信息
SELECT *
FROM student
WHERE StudentNo = 1000;
#WHERE中的比较运算符 < > <= >= != =
#示例4:查询生日在2000-01-01之后的学生信息
SELECT *
FROM student
WHERE BornDate > '2000-01-01';
#WHERE中逻辑运算符 AND OR NOT
#AND需要所有条件都满足
#示例5:查询班级编号是1,并且生日在1980-01-01之后,并且性别是1的学生信息
SELECT *
FROM student
WHERE GradeId = 1 AND BornDate > '1980-01-01' AND sex = 1;
#OR只要满足多条件之一即可
#示例6:查询班级编号是1,或者生日在1980-01-01之后,或者性别是1的学生信息
SELECT *
FROM student
WHERE GradeId = 1 OR BornDate > '1980-01-01' OR sex = 1;
#NOT表示取反
#示例7:查询邮箱不为空的学生的姓名,邮箱地址
SELECT StudentName "姓名",Email "邮箱地址"
FROM student
WHERE Email IS NOT NULL;
#示例8:查询生日在2000-2010之间的学生姓名
SELECT StudentName "姓名"
FROM student
WHERE BornDate >= '2000-01-01' AND BornDate <= '2010-01-01';
#示例9:使用BETWEEN关键字实现范围查询
SELECT StudentName "姓名"
FROM student
WHERE BornDate BETWEEN '2000-01-01' AND '2010-01-01';
#示例10:查询 班级是1或2或3班的学生姓名
SELECT StudentName "姓名"
FROM student
WHERE GradeId = 1 OR GradeId = 3 OR GradeId = 2;
#示例11:使用IN关键字进行匹配
SELECT StudentName "姓名"
FROM student
WHERE GradeId IN (1,2,3);
#LIKE关键字
#该关键字主要用于执行模糊查询,查询条件可以包含文字字符或占位符
#通过%表示匹配0或多个字符
#_表示匹配一个字符
#示例12:查询学生姓名 姓名以周开始,后面字符数量不定
SELECT StudentName "姓名"
FROM student
WHERE StudentName LIKE '李%';
# LIKE '%周' 以周字结束
# LIKE '%周%' 包含周字
# LIKE '周_' 以周开始且后方匹配一个字符
GROUP BY 分组查询
GROUP BY 字句的真正作用在于与各种聚合函数配合使用。它用来对查询出来的数据进行分组.
分组的真正含义:把表中列值相同的多条记录,当成是一条记录进行处理,最终也只输出一条记录,分组函数忽略空值
语法:
SELECT {*,列名,函数}
FROM 表名
[WHERE 基础条件]
[GROUP BY 分组条件]
[HAVING 过滤条件]
#示例1:统计各班人数
SELECT COUNT(*) "人数",GradeID "班级编号"
FROM student
WHERE sex = 1
GROUP BY (GradeID);
#示例2:统计每个学生的考试总分,平均分,最高分,最低分
SELECT StudentNo "学号", SUM(StudentResult) "总分",AVG(StudentResult) "平均分",MAX(StudentResult) "最高分",MIN(StudentResult) "平最低分"
FROM result
GROUP BY (StudentNo);
#示例3:考试时间在 2012年01月01日后 统计每个学生的考试总分,平均分,最高分,最低分
SELECT StudentNo "学号", SUM(StudentResult) "总分",AVG(StudentResult) "平均分",MAX(StudentResult) "最高分",MIN(StudentResult) "平最低分"
FROM result
WHERE ExamDate >= '2012-01-01'
GROUP BY (StudentNo);
#示例4:考试时间在 2012年01月01日后 统计每个学生的考试总分,平均分,最高分,最低分 过滤掉 总分在650以下的
SELECT StudentNo "学号", SUM(StudentResult) "总分",AVG(StudentResult) "平均分",MAX(StudentResult) "最高分",MIN(StudentResult) "平最低分"
FROM result
WHERE ExamDate >= '2012-01-01'
GROUP BY (StudentNo)
HAVING SUM(StudentResult) >= 650;
PS:分组函数的重要规则
1、如果 使用了分组函数,或使用了GROUP BY (字段1,字段2,...)执行查询,那么出现在SELECT 列表后的字段 要么必须是聚合函数,要么出现过在GRUOP字句内。
2、GRUOP BY子句的字段可以不出现在SELECT内。
3、使用聚合函数但不使用分组查询时,那么所有的数据会作为一组进行显示
4、GROUP BY前面的 WHERE 表示 分组前执行的条件过滤
5、GROUP BY后面的 HAVING表示 分组后执行的条件过滤
ORDER BY 排序查询
SELECT {*,列名,函数}
FROM 表名
[WHERE 基础条件]
[GROUP BY 分组条件]
[HAVING 过滤条件]
[ORDER BY (需要排序的字段) ASC||DESC]; #ASC升序(升序) DESC(降序)
#示例1、查询平均成绩在80以上的学生(学号)信息,同时成绩还需要按照降序排列
SELECT StudentNo "学号",AVG(StudentResult) "成绩"
FROM result
GROUP BY (StudentNo)
HAVING AVG(StudentResult) > 80;
ORDER BY(AVG(StudentResult)) DESC;
LIMIT 区间查询
SELECT {*,列名,函数}
FROM 表名
[WHERE 基础条件]
[GROUP BY 分组条件]
[HAVING 过滤条件]
[ORDER BY (需要排序的字段) ASC||DESC] #ASC升序(升序) DESC(降序)
[LIMIT A,B];
LIMIT 连续区间查询
LIMIT A,B A表示需要查询的行的索引位 B所查询的容量
LIMIT 0,5 第一行---第五
LIMIT 5,5 第六行---第十
LIMIT 10,5 第十一---第十五
分页查询的前置
以baidu热搜为例
>>>>>>>>>>>>> 第一页 LIMIT 0,6
>>>>>>>>>>>>> 第二页 LIMIT 6,6
>>>>>>>>>>>>> 第三页 LIMIT 12,6
>>>>>>>>>>>>> 第四页 LIMIT 18,6
>>>>>>>>>>>>> 第五页 LIMIT 24,6
>>>>>>>>>>>>> 第六页 LIMIT 30,6
>>>>>>>>>>>>> LIMIT (当前页码数-1)*容量,容量
#示例1:求学校学生中 三甲学生的信息
#分析 学生总分 降序排列 区间取前三
SELECT StudentNo "学号",SUM(StudentResult) "总成绩"
FROM result
GROUP BY (StudentNo)
ORDER BY(SUM(StudentResult)) DESC
LIMIT 0,3;
GROUP_CONCAT 分组数据合并
#示例1 根据班级进行分组,要求查看各班人数,以及各班学员姓名。
SELECT GradeID "班级编号",COUNT(*) "班级人数",GROUP_CONCAT(StudentName) "学员姓名"
FROM student
GROUP BY(GradeID);
注意事项:
1、使用GROUP_CONCAT()函数时必须要对数据源进行分组,如果不分组,所有数据都将合并成一行。
2、对结果集排序 查询语句执行的查询结果,数据是按照插入时顺序进行排序。
3、实际上需要按照某列大小值进行拍讯的话,建议只针对于数值或日期通过 ORDER BY函数进行排序
4、在语句最后也可以通过LIMIT控制容量大小
4.6 多表关联查询
1、交叉连接查询
#示例1:查询所有的学生+所有的班级信息
SELECT *
FROM student,grade;
这样查询最终得道的数据有11*7=77条数据
通过笛卡尔积获取的数据,异常过多,无法匹配具体的内容,于是我们需要补充条件以提高查询的精度
2、等值连接查询
#示例1:查询所有的学生+所有的班级信息
#语法:SELECT * FROM 表1,表2,... WHERE 表1.列 = 表2.列 [AND...];
SELECT *
FROM student,grade
WHERE student.GradeID = grade.GradeID;
#示例2:查询所有的学生姓名,住址,班级名称
SELECT StudentName "姓名",Address "住址",GradeName "班级名称"
FROM student,grade
WHERE student.GradeID = grade.GradeID;
#更为规范化的写法
SELECT s.StudentName "姓名",s.Address "住址",g.GradeName "班级名称"
FROM student s,grade g
WHERE s.GradeID = g.GradeID;
#练习查询学生姓名,参考科目,考试时间,考试成绩
#分析思路:1找到要查啥 2查的东西来自于哪 3表关系
SELECT s.StudentName "学生姓名",su.SubjectName "参考科目",r.ExamDate "考试时间",r.StudentResult "考试成绩"
FROM student s,subject su,result r
WHERE r.StudentNo = s.StudentNo AND r.SubjectNo = su.SubjectNo;
总结:等值链接确实能够帮助我们完成表于表之间的联系,但是WHERE这个关键字一开始是作为基础条件关键字出现的,而我们把表与表之间关系的描述通过WHERE去实施,难免大材小用.于是我们决定释放WHERE关于等值连接的操作。
3、内连接查询 INNER JOIN
#语法 SELECT * FROM 表1 INNER JOIN 表2 ON 表1.列 = 表2.列 [INNER JOIN 表3 ON 关系 .....][WHERE 基础条件];
#示例3:练习查询学生姓名,参考科目,考试时间,考试成绩
SELECT s.StudentName "学生姓名",su.SubjectName "参考科目",r.ExamDate "考试时间",r.StudentResult "考试成绩"
FROM student s INNER JOIN result r ON r.StudentNo = s.StudentNo
INNER JOIN subject su ON r.SubjectNo = su.SubjectNo;
PS 内连接查询的本质和等值实际上没有区别,但是内连接可以释放WHERE关键字,使表与表之间关系更加清晰.
4、外连接查询
4.1 左外连接 >>>>> LEFT JOIN 获取相交数据+左外关键字以左表的全部数据
SELECT s.StudentName "姓名",s.Address "住址",g.GradeName "班级名称"
FROM grade g LEFT JOIN student s ON s.GradeID = g.GradeID;
4.2 右外连接 >>>>> RIGHT JOIN 获取相交数据+右外关键字以右的全部数据
SELECT s.StudentName "姓名",s.Address "住址",g.GradeName "班级名称"
FROM student s RIGHT JOIN grade g ON s.GradeID = g.GradeID;
5、自然连接查询 自己和自己形成主外键关系
+------------+-----+-----------------+
| categoryId | pid | categoryName |
+------------+-----+-----------------+
| 2 | 1 | 美术设计 |
| 3 | 1 | 软件开发 |
| 4 | 3 | 数据库基础 |
| 5 | 2 | Photoshop基础 |
| 6 | 2 | 色彩搭配学 |
| 7 | 3 | PHP基础 |
| 8 | 3 | 一起学JAVA |
+------------+-----+-----------------+
假设 1 意味着是根目录
编号为2的美术设计 和编号为3的软件开发 父级都是 1 根目录
编号为3的数据库基础 是软件开发的一部分
SELECT c1.categoryName "父级目录",c2.categoryName "子栏目"
FROM category c1 INNER JOIN category c2 ON c1.categoryId = c2.pid;
子查询
1 将一个查询语句的结果充当下一个查询语句的条件
2 核心在于通过小括号以提高优先级别
3 子查询中可以包含的关键字 IN NOT ALL
4 子查询中可以包含的运算符 逻辑+算数
#示例1:查询大一的男生姓名及家庭住址
#1--大一对应的班级编号
SELECT GradeID FROM grade WHERE GradeName = '大一'; ======> 1
#2--以一年级一班对应的班级编号作为线索,去找适配的学生信息
SELECT StudentName "姓名",Address "住址"
FROM student WHERE GradeID = (SELECT GradeID FROM grade WHERE GradeName = '大一');
#3--加入我们的基础条件
SELECT StudentName "姓名",Address "住址"
FROM student WHERE GradeID = (SELECT GradeID FROM grade WHERE GradeName = '大一') AND sex = 1;
#示例2:查询班级名称是大一(学生信息==>学号信息),科目是高等数学-1(科目编号) 的学生的平均分
>>>>需求1 根据班级名 找出班级 编号
SELECT GradeID
FROM grade WHERE GradeName = '大一';
>>>>需求2 根据对应的班级编号 找到适配的学生学号
SELECT StudentNo
FROM student WHERE GradeID = (SELECT GradeID
FROM grade WHERE GradeName = '大一')
>>>>需求3 根据科目名找到对应的科目编号
SELECT subjectNo
FROM subject WHERE subjectName = '高等数学-1';
>>>>编辑最后的命令
SELECT AVG(result.StudentResult)
FROM result
WHERE result.SubjectNo = (SELECT subjectNo
FROM subject WHERE subjectName = '高等数学-1')
AND result.StudentNo IN (SELECT StudentNo
FROM student WHERE GradeID = (SELECT GradeID
FROM grade WHERE GradeName = '大一'));
4.7 SQL函数
聚合函数
聚合函数是指对一组值进行运算,最终返回是单个值。也可以被称为 组合函数
COUNT() 统计目标行数量的函数
AVG() 求平均值
SUM() 求合
MIN() 求最小值
MAX() 求最大值
PS:除COUNT函数之外,其他的聚合函数都会忽略NULL值
配套的示例 详见前文
面试题
COUNT(*) 和 COUNT(1) 和 COUNT(字段名) 三者区别
COUNT(*) 和 COUNT(1)
当表数据量较大时,对表进行检索,count1 时效要比 count* 慢
当表数据量较小时,对表进行检索,count1 时效要比 count* 快
count1 聚索引状
count* 自动选择索引
结论:这两个 通常 不予比较
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
COUNT(1) 和 COUNT(字段)
count1会统计表中所有的记录数,包含了字段为NULL的记录
count字段会忽略当前字段中出现null的情况,如果出现null值,不统计这条记录
三者区别
1.count(*) 包含了所有列,相当于所有行记录,在统计结果时不忽略NULL
2.count(1) 包含了所有的忽略列,用1表示代码行,在统计结果时不忽略NULL
3.count(字段) 只会包含具有列名的那一列,在统计结果时会忽略NULL
在执行效率上
如果列名<===>主键列
count(字段)>count(*)>count(1)
如果列名!<===>主键列
count(*)||count(1)>count(字段)
如果表多列都无主键
count(1)>count(*)>count(字段)
执行效率最高的
SELECT COUNT(主键列) .....
数值型函数
#随机生成 0-----99999的数字
#1随机生成一个数字 (0-1) 之间
SELECT RAND();
#2将生成的随机数*100000
SELECT RAND()*100000;
#3对结果进行FLOOR向下取整
SELECT FLOOR(RAND()*100000);
字符串函数
日期函数
#查询A学生和当前时间的天数差
SELECT DATEDIFF(NOW(),(SELECT BornDate FROM student WHERE StudentName = '张三'));
#根据生日查询其年龄
SELECT FLOOR(DATEDIFF(NOW(),(SELECT BornDate FROM student WHERE StudentName = '张三'))/365) AS "时差";
流程控制函数
#示例1
SELECT IF(12,2,3);
SELECT IF(1<2,'YES','NO');
SELECT IF(STRCMP('TEST001','TEST001'),'NO','YES');
条件内 结果 true(非0的自然数) false(0)
#示例2 分别显示学生信息,有邮箱和没有邮箱的备注信息
SELECT StudentName "学生姓名",IF(Email IS NULL,'没有邮箱','存在邮箱') "是否具有邮箱"
FROM student;
#示例3 使用IFNULL,函数入参两个,如果入参不为空则返回第一个值,否则返回第二个值
SELECT IFNULL(1,2),IFNULL(NULL,2),IFNULL(9/3,2);
SELECT StudentName "学生姓名",IFNULL(Email,'没有邮箱') "邮箱地址"
FROM student;
#示例4
CASE<表达式>
WHEN<值1> THEN<结果1>
WHEN<值2> THEN<结果2>
WHEN<值3> THEN<结果3>
WHEN<值4> THEN<结果4>
ELSE <默认结果>
END
#需求 查询成绩表 限定考试科目 高等数学-1
# 要求如下 如果学号是1000 显示成绩为原成绩的 1.5倍
# 要求如下 如果学号是1001 显示成绩为原成绩的 1.3倍
# 要求如下 如果学号是1002 显示成绩为原成绩的 1.1倍
# 要求如下 其他学生成绩显示原成绩
#1-查出高数-1的科目编号
SELECT SubjectNo FROM subject WHERE SubjectName = '高等数学-1';
#2-通过科目编号找到学生的考试成绩
SELECT * FROM result WHERE SubjectNo = (SELECT SubjectNo FROM subject WHERE SubjectName = '高等数学-1');
#3-通过CASE语法修改并查看参数
SELECT StudentNo "学号",StudentResult "原成绩",
CASE StudentNo
WHEN 1000 THEN StudentResult*1.5
WHEN 1001 THEN StudentResult*1.3
WHEN 1002 THEN StudentResult*1.1
ELSE StudentResult
END "修改后的成绩"
FROM result
WHERE SubjectNo = (SELECT SubjectNo FROM subject WHERE SubjectName = '高等数学-1');
#练习 为所有成绩进行评分 要求体现的内容有 学生姓名,参考科目,考试成绩,综合评分(>=90优 >=80良好 >=70中等 >=60较差 不及格)
#通过内连接 完成3表的关联 学生 成绩 科目
SELECT s.StudentName "学生姓名",su.SubjectName "参考科目",r.StudentResult "考试成绩",
CASE
WHEN r.StudentResult>=90 THEN "优秀"
WHEN r.StudentResult>=80 THEN "良好"
WHEN r.StudentResult>=70 THEN "中等"
WHEN r.StudentResult>=60 THEN "较差"
ELSE "不及格"
END "综合评分"
FROM student s INNER JOIN result r ON s.StudentNo = r.StudentNo
INNER JOIN subject su ON su.SubjectNo = r.SubjectNo;
以上所有示例及练习都是基于以下库表进行操作的
1:建库 MySchool_db
CREATE DATABASE Myschool_db;
2:建表(先主后从)
2.1创建年级表
CREATE TABLE grade(
GradeID INT NOT NULL AUTO_INCREMENT COMMENT '年级编号',
GradeName VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '年级名称',
PRIMARY KEY (GradeID)
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
2.2创建科目表
DROP TABLE IF EXISTS subject;
CREATE TABLE subject (
SubjectNo int NOT NULL AUTO_INCREMENT COMMENT '课程编号',
SubjectName varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '课程名称',
ClassHour int NULL DEFAULT NULL COMMENT '学时',
GradeID int NULL DEFAULT NULL COMMENT '年级编号',
PRIMARY KEY (SubjectNo)
) ENGINE = InnoDB AUTO_INCREMENT = 17 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
2.3创建学生表
DROP TABLE IF EXISTS student;
CREATE TABLE student (
StudentNo int(0) NOT NULL COMMENT '学号',
LoginPwd varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
StudentName varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '学生姓名',
Sex tinyint(1) NULL DEFAULT NULL COMMENT '性别,取值0或1',
GradeId int(0) NULL DEFAULT NULL COMMENT '年级编号',
Phone varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系电话,允许为空,即可选输入',
Address varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '地址,允许为空,即可选输入',
BornDate datetime(0) NULL DEFAULT NULL COMMENT '出生时间',
Email varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱账号,允许为空,即可选输入',
IdentityCard varchar(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '身份证号',
PRIMARY KEY (StudentNo) USING BTREE,
UNIQUE INDEX IdentityCard(IdentityCard) USING BTREE,
INDEX Email(Email) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
2.4创建成绩表
CREATE TABLE `result` (
`StudentNo` int(0) NOT NULL COMMENT '学号',
`SubjectNo` int(0) NOT NULL COMMENT '课程编号',
`ExamDate` datetime(0) NOT NULL COMMENT '考试日期',
`StudentResult` int(0) NOT NULL COMMENT '考试成绩',
INDEX `SubjectNo`(`SubjectNo`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>注入年级数据
INSERT INTO `grade` VALUES (1, '大一');
INSERT INTO `grade` VALUES (2, '大二');
INSERT INTO `grade` VALUES (3, '大三');
INSERT INTO `grade` VALUES (4, '大四');
INSERT INTO `grade` VALUES (5, '预科班');
INSERT INTO `grade` VALUES (6, '幼儿园');
INSERT INTO `grade` VALUES (7, '老年大学');
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>注入科目数据
INSERT INTO `subject` VALUES (1, '高等数学-1', 110, 1);
INSERT INTO `subject` VALUES (2, '高等数学-2', 110, 2);
INSERT INTO `subject` VALUES (3, '高等数学-3', 100, 3);
INSERT INTO `subject` VALUES (4, '高等数学-4', 130, 4);
INSERT INTO `subject` VALUES (5, 'C语言-1', 110, 1);
INSERT INTO `subject` VALUES (6, 'C语言-2', 110, 2);
INSERT INTO `subject` VALUES (7, 'C语言-3', 100, 3);
INSERT INTO `subject` VALUES (8, 'C语言-4', 130, 4);
INSERT INTO `subject` VALUES (9, 'JAVA第一学年', 110, 1);
INSERT INTO `subject` VALUES (10, 'JAVA第二学年', 110, 2);
INSERT INTO `subject` VALUES (11, 'JAVA第三学年', 100, 3);
INSERT INTO `subject` VALUES (12, 'JAVA第四学年', 130, 4);
INSERT INTO `subject` VALUES (13, '数据库结构-1', 110, 1);
INSERT INTO `subject` VALUES (14, '数据库结构-2', 110, 2);
INSERT INTO `subject` VALUES (15, '数据库结构-3', 100, 3);
INSERT INTO `subject` VALUES (16, '数据库结构-4', 130, 4);
INSERT INTO `subject` VALUES (17, 'C#基础', 130, 1);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>注入学生数据
INSERT INTO `student` VALUES (1000, '111111', '郭靖', 1, 1, '13500000001', '北京海淀区中关村大街1号', '1986-12-11 00:00:00', 'test1@openlab.cn', '450323198612111234');
INSERT INTO `student` VALUES (1001, '123456', '李文才', 1, 2, '12345678901', '广东广州天河区', '1981-12-31 00:00:00', 'test1@openlab.cn', '450323198112311234');
INSERT INTO `student` VALUES (1002, '111111', '李斯文', 1, 1, '13500000003', '天津市和平区', '1986-11-30 00:00:00', 'test1@openlab.cn', '450323198611301234');
INSERT INTO `student` VALUES (1003, '123456', '武松', 1, 3, '13500000004', '上海市金桥区', '1986-12-31 00:00:00', 'test1@openlab.cn', '450323198612314234');
INSERT INTO `student` VALUES (1004, '123456', '张三', 1, 4, '13500000005', '北京市通州', '1989-12-31 00:00:00', 'test1@openlab.cn', '450323198612311244');
INSERT INTO `student` VALUES (1005, '123456', '张秋丽 ', 2, 1, '13500000006', '广西桂林市灵川', '1986-12-31 00:00:00', 'test1@openlab.cn', '450323198612311214');
INSERT INTO `student` VALUES (9527, '888999', '赵尧林', 1, 1, '19988887777', '西安市雁塔区新家坡3号楼', '2000-01-01 00:00:00', 'zhaoyaolin@163.com', '610101200002029988');
INSERT INTO `student` VALUES (1007, '111111', '欧阳峻峰', 1, 1, '13500000008', '北京东城区', '1986-12-31 00:00:00', NULL, '450323198612311133');
INSERT INTO `student` VALUES (1008, '111111', '梅超风', 1, 1, '13500000009', '河南洛阳', '1986-12-31 00:00:00', NULL, '450323198612311221');
INSERT INTO `student` VALUES (1028, '111111', '赵敏', 1, 3, '13955556666', '西安市雁塔区', NULL, NULL, NULL);
INSERT INTO `student` VALUES (8080, '123123', '李寻欢', 1, 1, '13677778888', '西安市碑林区', '2005-05-01 00:00:00', 'litian@qq.com', '610101200505019900');
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>注入成绩信息
INSERT INTO `result` VALUES (1000, 1, '2013-11-11 16:00:00', 94);
INSERT INTO `result` VALUES (1000, 2, '2012-11-10 10:00:00', 75);
INSERT INTO `result` VALUES (1000, 3, '2011-12-19 10:00:00', 76);
INSERT INTO `result` VALUES (1000, 4, '2010-11-18 11:00:00', 93);
INSERT INTO `result` VALUES (1000, 5, '2013-11-11 14:00:00', 97);
INSERT INTO `result` VALUES (1000, 6, '2012-09-13 15:00:00', 87);
INSERT INTO `result` VALUES (1000, 7, '2011-10-16 16:00:00', 79);
INSERT INTO `result` VALUES (1000, 8, '2010-11-11 16:00:00', 74);
INSERT INTO `result` VALUES (1000, 9, '2013-11-21 10:00:00', 69);
INSERT INTO `result` VALUES (1000, 10, '2012-11-11 12:00:00', 78);
INSERT INTO `result` VALUES (1000, 11, '2011-11-11 14:00:00', 66);
INSERT INTO `result` VALUES (1000, 12, '2010-11-11 15:00:00', 82);
INSERT INTO `result` VALUES (1000, 13, '2013-11-11 14:00:00', 94);
INSERT INTO `result` VALUES (1000, 14, '2012-11-11 15:00:00', 98);
INSERT INTO `result` VALUES (1000, 15, '2011-12-11 10:00:00', 70);
INSERT INTO `result` VALUES (1000, 16, '2010-09-11 10:00:00', 74);
INSERT INTO `result` VALUES (1001, 1, '2013-11-11 16:00:00', 76);
INSERT INTO `result` VALUES (1001, 2, '2012-11-10 10:00:00', 93);
INSERT INTO `result` VALUES (1001, 3, '2011-12-19 10:00:00', 65);
INSERT INTO `result` VALUES (1001, 4, '2010-11-18 11:00:00', 71);
INSERT INTO `result` VALUES (1001, 5, '2013-11-11 14:00:00', 98);
INSERT INTO `result` VALUES (1001, 6, '2012-09-13 15:00:00', 74);
INSERT INTO `result` VALUES (1001, 7, '2011-10-16 16:00:00', 85);
INSERT INTO `result` VALUES (1001, 8, '2010-11-11 16:00:00', 69);
INSERT INTO `result` VALUES (1001, 9, '2013-11-21 10:00:00', 63);
INSERT INTO `result` VALUES (1001, 10, '2012-11-11 12:00:00', 70);
INSERT INTO `result` VALUES (1001, 11, '2011-11-11 14:00:00', 62);
INSERT INTO `result` VALUES (1001, 12, '2010-11-11 15:00:00', 90);
INSERT INTO `result` VALUES (1001, 13, '2013-11-11 14:00:00', 97);
INSERT INTO `result` VALUES (1001, 14, '2012-11-11 15:00:00', 89);
INSERT INTO `result` VALUES (1001, 15, '2011-12-11 10:00:00', 72);
INSERT INTO `result` VALUES (1001, 16, '2010-09-11 10:00:00', 90);
INSERT INTO `result` VALUES (1002, 1, '2013-11-11 16:00:00', 61);
INSERT INTO `result` VALUES (1002, 2, '2012-11-10 10:00:00', 80);
INSERT INTO `result` VALUES (1002, 3, '2011-12-19 10:00:00', 89);
INSERT INTO `result` VALUES (1002, 4, '2010-11-18 11:00:00', 88);
INSERT INTO `result` VALUES (1002, 5, '2013-11-11 14:00:00', 82);
INSERT INTO `result` VALUES (1002, 6, '2012-09-13 15:00:00', 91);
INSERT INTO `result` VALUES (1002, 7, '2011-10-16 16:00:00', 63);
INSERT INTO `result` VALUES (1002, 8, '2010-11-11 16:00:00', 84);
INSERT INTO `result` VALUES (1002, 9, '2013-11-21 10:00:00', 60);
INSERT INTO `result` VALUES (1002, 10, '2012-11-11 12:00:00', 71);
INSERT INTO `result` VALUES (1002, 11, '2011-11-11 14:00:00', 93);
INSERT INTO `result` VALUES (1002, 12, '2010-11-11 15:00:00', 96);
INSERT INTO `result` VALUES (1002, 13, '2013-11-11 14:00:00', 83);
INSERT INTO `result` VALUES (1002, 14, '2012-11-11 15:00:00', 69);
INSERT INTO `result` VALUES (1002, 15, '2011-12-11 10:00:00', 89);
INSERT INTO `result` VALUES (1002, 16, '2010-09-11 10:00:00', 83);
INSERT INTO `result` VALUES (1003, 1, '2013-11-11 16:00:00', 91);
INSERT INTO `result` VALUES (1003, 2, '2012-11-10 10:00:00', 75);
INSERT INTO `result` VALUES (1003, 3, '2011-12-19 10:00:00', 65);
INSERT INTO `result` VALUES (1003, 4, '2010-11-18 11:00:00', 63);
INSERT INTO `result` VALUES (1003, 5, '2013-11-11 14:00:00', 90);
INSERT INTO `result` VALUES (1003, 6, '2012-09-13 15:00:00', 96);
INSERT INTO `result` VALUES (1003, 7, '2011-10-16 16:00:00', 97);
INSERT INTO `result` VALUES (1003, 8, '2010-11-11 16:00:00', 77);
INSERT INTO `result` VALUES (1003, 9, '2013-11-21 10:00:00', 62);
INSERT INTO `result` VALUES (1003, 10, '2012-11-11 12:00:00', 81);
INSERT INTO `result` VALUES (1003, 11, '2011-11-11 14:00:00', 76);
INSERT INTO `result` VALUES (1003, 12, '2010-11-11 15:00:00', 61);
INSERT INTO `result` VALUES (1003, 13, '2013-11-11 14:00:00', 93);
INSERT INTO `result` VALUES (1003, 14, '2012-11-11 15:00:00', 79);
INSERT INTO `result` VALUES (1003, 15, '2011-12-11 10:00:00', 78);
INSERT INTO `result` VALUES (1003, 16, '2010-09-11 10:00:00', 96);
INSERT INTO `result` VALUES (1004, 1, '2013-11-11 16:00:00', 84);
INSERT INTO `result` VALUES (1004, 2, '2012-11-10 10:00:00', 79);
INSERT INTO `result` VALUES (1004, 3, '2011-12-19 10:00:00', 76);
INSERT INTO `result` VALUES (1004, 4, '2010-11-18 11:00:00', 78);
INSERT INTO `result` VALUES (1004, 5, '2013-11-11 14:00:00', 81);
INSERT INTO `result` VALUES (1004, 6, '2012-09-13 15:00:00', 90);
INSERT INTO `result` VALUES (1004, 7, '2011-10-16 16:00:00', 63);
INSERT INTO `result` VALUES (1004, 8, '2010-11-11 16:00:00', 89);
INSERT INTO `result` VALUES (1004, 9, '2013-11-21 10:00:00', 67);
INSERT INTO `result` VALUES (1004, 10, '2012-11-11 12:00:00', 100);
INSERT INTO `result` VALUES (1004, 11, '2011-11-11 14:00:00', 94);
INSERT INTO `result` VALUES (1004, 12, '2010-11-11 15:00:00', 65);
INSERT INTO `result` VALUES (1004, 13, '2013-11-11 14:00:00', 86);
INSERT INTO `result` VALUES (1004, 14, '2012-11-11 15:00:00', 77);
INSERT INTO `result` VALUES (1004, 15, '2011-12-11 10:00:00', 82);
INSERT INTO `result` VALUES (1004, 16, '2010-09-11 10:00:00', 87);
INSERT INTO `result` VALUES (1005, 1, '2013-11-11 16:00:00', 82);
INSERT INTO `result` VALUES (1005, 2, '2012-11-10 10:00:00', 92);
INSERT INTO `result` VALUES (1005, 3, '2011-12-19 10:00:00', 80);
INSERT INTO `result` VALUES (1005, 4, '2010-11-18 11:00:00', 92);
INSERT INTO `result` VALUES (1005, 5, '2013-11-11 14:00:00', 97);
INSERT INTO `result` VALUES (1005, 6, '2012-09-13 15:00:00', 72);
INSERT INTO `result` VALUES (1005, 7, '2011-10-16 16:00:00', 84);
INSERT INTO `result` VALUES (1005, 8, '2010-11-11 16:00:00', 79);
INSERT INTO `result` VALUES (1005, 9, '2013-11-21 10:00:00', 76);
INSERT INTO `result` VALUES (1005, 10, '2012-11-11 12:00:00', 87);
INSERT INTO `result` VALUES (1005, 11, '2011-11-11 14:00:00', 65);
INSERT INTO `result` VALUES (1005, 12, '2010-11-11 15:00:00', 67);
INSERT INTO `result` VALUES (1005, 13, '2013-11-11 14:00:00', 63);
INSERT INTO `result` VALUES (1005, 14, '2012-11-11 15:00:00', 64);
INSERT INTO `result` VALUES (1005, 15, '2011-12-11 10:00:00', 99);
INSERT INTO `result` VALUES (1005, 16, '2010-09-11 10:00:00', 97);
INSERT INTO `result` VALUES (1006, 1, '2013-11-11 16:00:00', 82);
INSERT INTO `result` VALUES (1006, 2, '2012-11-10 10:00:00', 73);
INSERT INTO `result` VALUES (1006, 3, '2011-12-19 10:00:00', 79);
INSERT INTO `result` VALUES (1006, 4, '2010-11-18 11:00:00', 63);
INSERT INTO `result` VALUES (1006, 5, '2013-11-11 14:00:00', 97);
INSERT INTO `result` VALUES (1006, 6, '2012-09-13 15:00:00', 83);
INSERT INTO `result` VALUES (1006, 7, '2011-10-16 16:00:00', 78);
INSERT INTO `result` VALUES (1006, 8, '2010-11-11 16:00:00', 88);
INSERT INTO `result` VALUES (1006, 9, '2013-11-21 10:00:00', 89);
INSERT INTO `result` VALUES (1006, 10, '2012-11-11 12:00:00', 82);
INSERT INTO `result` VALUES (1006, 11, '2011-11-11 14:00:00', 70);
INSERT INTO `result` VALUES (1006, 12, '2010-11-11 15:00:00', 69);
INSERT INTO `result` VALUES (1006, 13, '2013-11-11 14:00:00', 64);
INSERT INTO `result` VALUES (1006, 14, '2012-11-11 15:00:00', 80);
INSERT INTO `result` VALUES (1006, 15, '2011-12-11 10:00:00', 90);
INSERT INTO `result` VALUES (1006, 16, '2010-09-11 10:00:00', 85);
INSERT INTO `result` VALUES (1007, 1, '2013-11-11 16:00:00', 87);
INSERT INTO `result` VALUES (1007, 2, '2012-11-10 10:00:00', 63);
INSERT INTO `result` VALUES (1007, 3, '2011-12-19 10:00:00', 70);
INSERT INTO `result` VALUES (1007, 4, '2010-11-18 11:00:00', 74);
INSERT INTO `result` VALUES (1007, 5, '2013-11-11 14:00:00', 79);
INSERT INTO `result` VALUES (1007, 6, '2012-09-13 15:00:00', 83);
INSERT INTO `result` VALUES (1007, 7, '2011-10-16 16:00:00', 86);
INSERT INTO `result` VALUES (1007, 8, '2010-11-11 16:00:00', 76);
INSERT INTO `result` VALUES (1007, 9, '2013-11-21 10:00:00', 65);
INSERT INTO `result` VALUES (1007, 10, '2012-11-11 12:00:00', 87);
INSERT INTO `result` VALUES (1007, 11, '2011-11-11 14:00:00', 69);
INSERT INTO `result` VALUES (1007, 12, '2010-11-11 15:00:00', 69);
INSERT INTO `result` VALUES (1007, 13, '2013-11-11 14:00:00', 90);
INSERT INTO `result` VALUES (1007, 14, '2012-11-11 15:00:00', 84);
INSERT INTO `result` VALUES (1007, 15, '2011-12-11 10:00:00', 95);
INSERT INTO `result` VALUES (1007, 16, '2010-09-11 10:00:00', 92);
INSERT INTO `result` VALUES (1008, 1, '2013-11-11 16:00:00', 96);
INSERT INTO `result` VALUES (1008, 2, '2012-11-10 10:00:00', 62);
INSERT INTO `result` VALUES (1008, 3, '2011-12-19 10:00:00', 97);
INSERT INTO `result` VALUES (1008, 4, '2010-11-18 11:00:00', 84);
INSERT INTO `result` VALUES (1008, 5, '2013-11-11 14:00:00', 86);
INSERT INTO `result` VALUES (1008, 6, '2012-09-13 15:00:00', 72);
INSERT INTO `result` VALUES (1008, 7, '2011-10-16 16:00:00', 67);
INSERT INTO `result` VALUES (1008, 8, '2010-11-11 16:00:00', 83);
INSERT INTO `result` VALUES (1008, 9, '2013-11-21 10:00:00', 86);
INSERT INTO `result` VALUES (1008, 10, '2012-11-11 12:00:00', 60);
INSERT INTO `result` VALUES (1008, 11, '2011-11-11 14:00:00', 61);
INSERT INTO `result` VALUES (1008, 12, '2010-11-11 15:00:00', 68);
INSERT INTO `result` VALUES (1008, 13, '2013-11-11 14:00:00', 99);
INSERT INTO `result` VALUES (1008, 14, '2012-11-11 15:00:00', 77);
INSERT INTO `result` VALUES (1008, 15, '2011-12-11 10:00:00', 73);
INSERT INTO `result` VALUES (1008, 16, '2010-09-11 10:00:00', 78);
INSERT INTO `result` VALUES (1009, 1, '2013-11-11 16:00:00', 67);
INSERT INTO `result` VALUES (1009, 2, '2012-11-10 10:00:00', 70);
INSERT INTO `result` VALUES (1009, 3, '2011-12-19 10:00:00', 75);
INSERT INTO `result` VALUES (1009, 4, '2010-11-18 11:00:00', 92);
INSERT INTO `result` VALUES (1009, 5, '2013-11-11 14:00:00', 76);
INSERT INTO `result` VALUES (1009, 6, '2012-09-13 15:00:00', 90);
INSERT INTO `result` VALUES (1009, 7, '2011-10-16 16:00:00', 62);
INSERT INTO `result` VALUES (1009, 8, '2010-11-11 16:00:00', 68);
INSERT INTO `result` VALUES (1009, 9, '2013-11-21 10:00:00', 70);
INSERT INTO `result` VALUES (1009, 10, '2012-11-11 12:00:00', 83);
INSERT INTO `result` VALUES (1009, 11, '2011-11-11 14:00:00', 88);
INSERT INTO `result` VALUES (1009, 12, '2010-11-11 15:00:00', 65);
INSERT INTO `result` VALUES (1009, 13, '2013-11-11 14:00:00', 91);
INSERT INTO `result` VALUES (1009, 14, '2012-11-11 15:00:00', 99);
INSERT INTO `result` VALUES (1009, 15, '2011-12-11 10:00:00', 65);
INSERT INTO `result` VALUES (1009, 16, '2010-09-11 10:00:00', 83);
INSERT INTO `result` VALUES (1010, 1, '2013-11-11 16:00:00', 83);
INSERT INTO `result` VALUES (1010, 2, '2012-11-10 10:00:00', 87);
INSERT INTO `result` VALUES (1010, 3, '2011-12-19 10:00:00', 89);
INSERT INTO `result` VALUES (1010, 4, '2010-11-18 11:00:00', 99);
INSERT INTO `result` VALUES (1010, 5, '2013-11-11 14:00:00', 91);
INSERT INTO `result` VALUES (1010, 6, '2012-09-13 15:00:00', 96);
INSERT INTO `result` VALUES (1010, 7, '2011-10-16 16:00:00', 72);
INSERT INTO `result` VALUES (1010, 8, '2010-11-11 16:00:00', 72);
INSERT INTO `result` VALUES (1010, 9, '2013-11-21 10:00:00', 98);
INSERT INTO `result` VALUES (1010, 10, '2012-11-11 12:00:00', 73);
INSERT INTO `result` VALUES (1010, 11, '2011-11-11 14:00:00', 68);
INSERT INTO `result` VALUES (1010, 12, '2010-11-11 15:00:00', 62);
INSERT INTO `result` VALUES (1010, 13, '2013-11-11 14:00:00', 67);
INSERT INTO `result` VALUES (1010, 14, '2012-11-11 15:00:00', 69);
INSERT INTO `result` VALUES (1010, 15, '2011-12-11 10:00:00', 71);
INSERT INTO `result` VALUES (1010, 16, '2010-09-11 10:00:00', 66);
INSERT INTO `result` VALUES (1011, 1, '2013-11-11 16:00:00', 62);
INSERT INTO `result` VALUES (1011, 2, '2012-11-10 10:00:00', 72);
INSERT INTO `result` VALUES (1011, 3, '2011-12-19 10:00:00', 96);
INSERT INTO `result` VALUES (1011, 4, '2010-11-18 11:00:00', 64);
INSERT INTO `result` VALUES (1011, 5, '2013-11-11 14:00:00', 89);
INSERT INTO `result` VALUES (1011, 6, '2012-09-13 15:00:00', 91);
INSERT INTO `result` VALUES (1011, 7, '2011-10-16 16:00:00', 95);
INSERT INTO `result` VALUES (1011, 8, '2010-11-11 16:00:00', 96);
INSERT INTO `result` VALUES (1011, 9, '2013-11-21 10:00:00', 89);
INSERT INTO `result` VALUES (1011, 10, '2012-11-11 12:00:00', 73);
INSERT INTO `result` VALUES (1011, 11, '2011-11-11 14:00:00', 82);
INSERT INTO `result` VALUES (1011, 12, '2010-11-11 15:00:00', 98);
INSERT INTO `result` VALUES (1011, 13, '2013-11-11 14:00:00', 66);
INSERT INTO `result` VALUES (1011, 14, '2012-11-11 15:00:00', 69);
INSERT INTO `result` VALUES (1011, 15, '2011-12-11 10:00:00', 91);
INSERT INTO `result` VALUES (1011, 16, '2010-09-11 10:00:00', 69);
INSERT INTO `result` VALUES (1012, 1, '2013-11-11 16:00:00', 86);
INSERT INTO `result` VALUES (1012, 2, '2012-11-10 10:00:00', 66);
INSERT INTO `result` VALUES (1012, 3, '2011-12-19 10:00:00', 97);
INSERT INTO `result` VALUES (1012, 4, '2010-11-18 11:00:00', 69);
INSERT INTO `result` VALUES (1012, 5, '2013-11-11 14:00:00', 70);
INSERT INTO `result` VALUES (1012, 6, '2012-09-13 15:00:00', 74);
INSERT INTO `result` VALUES (1012, 7, '2011-10-16 16:00:00', 91);
INSERT INTO `result` VALUES (1012, 8, '2010-11-11 16:00:00', 97);
INSERT INTO `result` VALUES (1012, 9, '2013-11-21 10:00:00', 84);
INSERT INTO `result` VALUES (1012, 10, '2012-11-11 12:00:00', 82);
INSERT INTO `result` VALUES (1012, 11, '2011-11-11 14:00:00', 90);
INSERT INTO `result` VALUES (1012, 12, '2010-11-11 15:00:00', 91);
INSERT INTO `result` VALUES (1012, 13, '2013-11-11 14:00:00', 91);
INSERT INTO `result` VALUES (1012, 14, '2012-11-11 15:00:00', 97);
INSERT INTO `result` VALUES (1012, 15, '2011-12-11 10:00:00', 85);
INSERT INTO `result` VALUES (1012, 16, '2010-09-11 10:00:00', 90);
INSERT INTO `result` VALUES (1013, 1, '2013-11-11 16:00:00', 73);
INSERT INTO `result` VALUES (1013, 2, '2012-11-10 10:00:00', 69);
INSERT INTO `result` VALUES (1013, 3, '2011-12-19 10:00:00', 91);
INSERT INTO `result` VALUES (1013, 4, '2010-11-18 11:00:00', 72);
INSERT INTO `result` VALUES (1013, 5, '2013-11-11 14:00:00', 76);
INSERT INTO `result` VALUES (1013, 6, '2012-09-13 15:00:00', 87);
INSERT INTO `result` VALUES (1013, 7, '2011-10-16 16:00:00', 61);
INSERT INTO `result` VALUES (1013, 8, '2010-11-11 16:00:00', 77);
INSERT INTO `result` VALUES (1013, 9, '2013-11-21 10:00:00', 83);
INSERT INTO `result` VALUES (1013, 10, '2012-11-11 12:00:00', 99);
INSERT INTO `result` VALUES (1013, 11, '2011-11-11 14:00:00', 91);
INSERT INTO `result` VALUES (1013, 12, '2010-11-11 15:00:00', 84);
INSERT INTO `result` VALUES (1013, 13, '2013-11-11 14:00:00', 98);
INSERT INTO `result` VALUES (1013, 14, '2012-11-11 15:00:00', 74);
INSERT INTO `result` VALUES (1013, 15, '2011-12-11 10:00:00', 92);
INSERT INTO `result` VALUES (1013, 16, '2010-09-11 10:00:00', 90);
INSERT INTO `result` VALUES (1014, 1, '2013-11-11 16:00:00', 64);
INSERT INTO `result` VALUES (1014, 2, '2012-11-10 10:00:00', 81);
INSERT INTO `result` VALUES (1014, 3, '2011-12-19 10:00:00', 79);
INSERT INTO `result` VALUES (1014, 4, '2010-11-18 11:00:00', 74);
INSERT INTO `result` VALUES (1014, 5, '2013-11-11 14:00:00', 65);
INSERT INTO `result` VALUES (1014, 6, '2012-09-13 15:00:00', 88);
INSERT INTO `result` VALUES (1014, 7, '2011-10-16 16:00:00', 86);
INSERT INTO `result` VALUES (1014, 8, '2010-11-11 16:00:00', 77);
INSERT INTO `result` VALUES (1014, 9, '2013-11-21 10:00:00', 86);
INSERT INTO `result` VALUES (1014, 10, '2012-11-11 12:00:00', 85);
INSERT INTO `result` VALUES (1014, 11, '2011-11-11 14:00:00', 86);
INSERT INTO `result` VALUES (1014, 12, '2010-11-11 15:00:00', 75);
INSERT INTO `result` VALUES (1014, 13, '2013-11-11 14:00:00', 89);
INSERT INTO `result` VALUES (1014, 14, '2012-11-11 15:00:00', 79);
INSERT INTO `result` VALUES (1014, 15, '2011-12-11 10:00:00', 73);
INSERT INTO `result` VALUES (1014, 16, '2010-09-11 10:00:00', 68);
INSERT INTO `result` VALUES (1015, 1, '2013-11-11 16:00:00', 99);
INSERT INTO `result` VALUES (1015, 2, '2012-11-10 10:00:00', 60);
INSERT INTO `result` VALUES (1015, 3, '2011-12-19 10:00:00', 60);
INSERT INTO `result` VALUES (1015, 4, '2010-11-18 11:00:00', 75);
INSERT INTO `result` VALUES (1015, 5, '2013-11-11 14:00:00', 78);
INSERT INTO `result` VALUES (1015, 6, '2012-09-13 15:00:00', 78);
INSERT INTO `result` VALUES (1015, 7, '2011-10-16 16:00:00', 84);
INSERT INTO `result` VALUES (1015, 8, '2010-11-11 16:00:00', 95);
INSERT INTO `result` VALUES (1015, 9, '2013-11-21 10:00:00', 93);
INSERT INTO `result` VALUES (1015, 10, '2012-11-11 12:00:00', 79);
INSERT INTO `result` VALUES (1015, 11, '2011-11-11 14:00:00', 74);
INSERT INTO `result` VALUES (1015, 12, '2010-11-11 15:00:00', 65);
INSERT INTO `result` VALUES (1015, 13, '2013-11-11 14:00:00', 63);
INSERT INTO `result` VALUES (1015, 14, '2012-11-11 15:00:00', 74);
INSERT INTO `result` VALUES (1015, 15, '2011-12-11 10:00:00', 67);
INSERT INTO `result` VALUES (1015, 16, '2010-09-11 10:00:00', 65);
INSERT INTO `result` VALUES (1016, 1, '2013-11-11 16:00:00', 97);
INSERT INTO `result` VALUES (1016, 2, '2012-11-10 10:00:00', 90);
INSERT INTO `result` VALUES (1016, 3, '2011-12-19 10:00:00', 77);
INSERT INTO `result` VALUES (1016, 4, '2010-11-18 11:00:00', 75);
INSERT INTO `result` VALUES (1016, 5, '2013-11-11 14:00:00', 75);
INSERT INTO `result` VALUES (1016, 6, '2012-09-13 15:00:00', 97);
INSERT INTO `result` VALUES (1016, 7, '2011-10-16 16:00:00', 96);
INSERT INTO `result` VALUES (1016, 8, '2010-11-11 16:00:00', 92);
INSERT INTO `result` VALUES (1016, 9, '2013-11-21 10:00:00', 62);
INSERT INTO `result` VALUES (1016, 10, '2012-11-11 12:00:00', 83);
INSERT INTO `result` VALUES (1016, 11, '2011-11-11 14:00:00', 98);
INSERT INTO `result` VALUES (1016, 12, '2010-11-11 15:00:00', 94);
INSERT INTO `result` VALUES (1016, 13, '2013-11-11 14:00:00', 62);
INSERT INTO `result` VALUES (1016, 14, '2012-11-11 15:00:00', 97);
INSERT INTO `result` VALUES (1016, 15, '2011-12-11 10:00:00', 76);
INSERT INTO `result` VALUES (1016, 16, '2010-09-11 10:00:00', 82);
INSERT INTO `result` VALUES (1017, 1, '2013-11-11 16:00:00', 100);
INSERT INTO `result` VALUES (1017, 2, '2012-11-10 10:00:00', 88);
INSERT INTO `result` VALUES (1017, 3, '2011-12-19 10:00:00', 86);
INSERT INTO `result` VALUES (1017, 4, '2010-11-18 11:00:00', 73);
INSERT INTO `result` VALUES (1017, 5, '2013-11-11 14:00:00', 96);
INSERT INTO `result` VALUES (1017, 6, '2012-09-13 15:00:00', 64);
INSERT INTO `result` VALUES (1017, 7, '2011-10-16 16:00:00', 81);
INSERT INTO `result` VALUES (1017, 8, '2010-11-11 16:00:00', 66);
INSERT INTO `result` VALUES (1017, 9, '2013-11-21 10:00:00', 76);
INSERT INTO `result` VALUES (1017, 10, '2012-11-11 12:00:00', 95);
INSERT INTO `result` VALUES (1017, 11, '2011-11-11 14:00:00', 73);
INSERT INTO `result` VALUES (1017, 12, '2010-11-11 15:00:00', 82);
INSERT INTO `result` VALUES (1017, 13, '2013-11-11 14:00:00', 85);
INSERT INTO `result` VALUES (1017, 14, '2012-11-11 15:00:00', 68);
INSERT INTO `result` VALUES (1017, 15, '2011-12-11 10:00:00', 99);
INSERT INTO `result` VALUES (1017, 16, '2010-09-11 10:00:00', 76);