Skip to content

Commit fe71d27

Browse files
committed
修复了部分文档和代码中的bug
1 parent 43c147d commit fe71d27

File tree

5 files changed

+148
-44
lines changed

5 files changed

+148
-44
lines changed

Day01-15/Day04/code/for1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88

99
sum = 0
1010
for x in range(1, 101):
11-
if x % 2 == 0:
12-
sum += x
11+
sum += x
1312
print(sum)

Day16-20/Python语言进阶.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@
555555

556556
```Python
557557
from functools import wraps
558+
from threading import Lock
558559

559560

560561
def singleton(cls):

Day36-40/code/SRS_create_and_init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ select stuname as 姓名, year(now())-year(stubirth) as 年龄 from tb_student w
216216
);
217217

218218
-- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算)
219-
select stuname from tb_student where stuid=(
219+
select stuname from tb_student where stuid in (
220220
select stuid from tb_score group by stuid having count(stuid)>2
221221
)
222222

Day36-40/code/学校选课系统.spf

Lines changed: 144 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<dict>
1111
<key>connection</key>
1212
<dict>
13-
<key>database</key>
14-
<string>school</string>
1513
<key>host</key>
1614
<string>120.77.222.217</string>
1715
<key>kcid</key>
@@ -47,22 +45,17 @@
4745
<integer>1</integer>
4846
<key>contentSelection</key>
4947
<data>
50-
YnBsaXN0MDDUAQIDBAUGOTpYJHZlcnNpb25YJG9iamVjdHNZJGFy
51-
Y2hpdmVyVCR0b3ASAAGGoK0HCBUWFxgZHSQoLDE2VSRudWxs0wkK
52-
CwwQFFdOUy5rZXlzWk5TLm9iamVjdHNWJGNsYXNzow0OD4ACgAOA
53-
BKMREhOABYAGgAiADFR0eXBlVHJvd3NUa2V5c18QJlNlbGVjdGlv
54-
bkRldGFpbFR5cGVQcmlt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AVQBgAGcAagBsAG4AcQBzAHUAdwB8AIEAoQCmALMA
57+
tQC3ALwAxwDQANsA3gDpAPIA9wEEAQcBEAEiASUBKgAAAAAAAAIB
58+
AAAAAAAAACkAAAAAAAAAAAAAAAAAAAEs
6659
</data>
6760
<key>contentSortColIsAsc</key>
6861
<true/>
@@ -289,7 +282,7 @@ select stuname as 姓名, year(now())-year(stubirth) as 年龄 from tb_student w
289282
);
290283

291284
-- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算)
292-
select stuname from tb_student where stuid=(
285+
explain select stuname from tb_student where stuid in (
293286
select stuid from tb_score group by stuid having count(stuid)&gt;2
294287
)
295288

@@ -314,8 +307,6 @@ select stuname, avgmark from tb_student t1 inner join
314307
-- 查询每个学生的姓名和选课数量(左外连接和子查询)
315308
select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid;
316309
</string>
317-
<key>table</key>
318-
<string>tb_score</string>
319310
<key>view</key>
320311
<string>SP_VIEW_CUSTOMQUERY</string>
321312
<key>windowVerticalDividerPosition</key>
@@ -330,6 +321,137 @@ select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stui
330321
<array/>
331322
<key>queryHistory</key>
332323
<array>
324+
<string>-- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算)
325+
explain select stuname from tb_student where stuid=any(
326+
select stuid from tb_score group by stuid having count(stuid)&gt;2
327+
)</string>
328+
<string>explain select stuname from tb_student where stuid in (
329+
select stuid from tb_score group by stuid having count(stuid)&gt;2
330+
)</string>
331+
<string>select stuname from tb_student where stuid in (
332+
select stuid from tb_score group by stuid having count(stuid)&gt;2
333+
)</string>
334+
<string>select stuname from tb_student where stuid=(
335+
select stuid from tb_score group by stuid having count(stuid)&gt;2
336+
)</string>
337+
<string>-- 如果存在名为school的数据库就删除它
338+
drop database if exists school;
339+
-- 创建名为school的数据库并设置默认的字符集和排序方式
340+
create database school default charset utf8 collate utf8_bin;
341+
-- 切换到school数据库上下文环境
342+
use school;
343+
-- 创建学院表
344+
create table tb_college
345+
(
346+
collid int not null auto_increment comment '编号',
347+
collname varchar(50) not null comment '名称',
348+
collmaster varchar(20) not null comment '院长',
349+
collweb varchar(511) default '' comment '网站',
350+
primary key (collid)
351+
);
352+
-- 创建学生表
353+
create table tb_student
354+
(
355+
stuid int not null comment '学号',
356+
stuname varchar(20) not null comment '姓名',
357+
stusex bit default 1 comment '性别',
358+
stubirth date not null comment '出生日期',
359+
stuaddr varchar(255) default '' comment '籍贯',
360+
collid int not null comment '所属学院',
361+
primary key (stuid),
362+
foreign key (collid) references tb_college (collid)
363+
);
364+
-- alter table tb_student add constraint fk_student_collid foreign key (collid) references tb_college (collid);
365+
366+
-- 创建教师表
367+
create table tb_teacher
368+
(
369+
teaid int not null comment '工号',
370+
teaname varchar(20) not null comment '姓名',
371+
teatitle varchar(10) default '助教' comment '职称',
372+
collid int not null comment '所属学院',
373+
primary key (teaid),
374+
foreign key (collid) references tb_college (collid)
375+
);
376+
-- 创建课程表
377+
create table tb_course
378+
(
379+
couid int not null comment '编号',
380+
couname varchar(50) not null comment '名称',
381+
coucredit int not null comment '学分',
382+
teaid int not null comment '授课老师',
383+
primary key (couid),
384+
foreign key (teaid) references tb_teacher (teaid)
385+
);
386+
-- 创建选课记录表
387+
create table tb_score
388+
(
389+
scid int auto_increment comment '选课记录编号',
390+
stuid int not null comment '选课学生',
391+
couid int not null comment '所选课程',
392+
scdate datetime comment '选课时间日期',
393+
scmark decimal(4,1) comment '考试成绩',
394+
primary key (scid),
395+
foreign key (stuid) references tb_student (stuid),
396+
foreign key (couid) references tb_course (couid)
397+
);
398+
-- 添加唯一性约束(一个学生选某个课程只能选一次)
399+
alter table tb_score add constraint uni_score_stuid_couid unique (stuid, couid);
400+
-- 插入学院数据
401+
insert into tb_college (collname, collmaster, collweb) values
402+
('计算机学院', '左冷禅', 'http://www.abc.com'),
403+
('外国语学院', '岳不群', 'http://www.xyz.com'),
404+
('经济管理学院', '风清扬', 'http://www.foo.com');
405+
-- 插入学生数据
406+
insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid) values
407+
(1001, '杨逍', 1, '1990-3-4', '四川成都', 1),
408+
(1002, '任我行', 1, '1992-2-2', '湖南长沙', 1),
409+
(1033, '王语嫣', 0, '1989-12-3', '四川成都', 1),
410+
(1572, '岳不群', 1, '1993-7-19', '陕西咸阳', 1),
411+
(1378, '纪嫣然', 0, '1995-8-12', '四川绵阳', 1),
412+
(1954, '林平之', 1, '1994-9-20', '福建莆田', 1),
413+
(2035, '东方不败', 1, '1988-6-30', null, 2),
414+
(3011, '林震南', 1, '1985-12-12', '福建莆田', 3),
415+
(3755, '项少龙', 1, '1993-1-25', null, 3),
416+
(3923, '杨不悔', 0, '1985-4-17', '四川成都', 3);
417+
-- 插入老师数据
418+
insert into tb_teacher (teaid, teaname, teatitle, collid) values
419+
(1122, '张三丰', '教授', 1),
420+
(1133, '宋远桥', '副教授', 1),
421+
(1144, '杨逍', '副教授', 1),
422+
(2255, '范遥', '副教授', 2),
423+
(3366, '韦一笑', '讲师', 3);
424+
-- 插入课程数据
425+
insert into tb_course (couid, couname, coucredit, teaid) values
426+
(1111, 'Python程序设计', 3, 1122),
427+
(2222, 'Web前端开发', 2, 1122),
428+
(3333, '操作系统', 4, 1122),
429+
(4444, '计算机网络', 2, 1133),
430+
(5555, '编译原理', 4, 1144),
431+
(6666, '算法和数据结构', 3, 1144),
432+
(7777, '经贸法语', 3, 2255),
433+
(8888, '成本会计', 2, 3366),
434+
(9999, '审计学', 3, 3366);
435+
-- 插入选课数据
436+
insert into tb_score (stuid, couid, scdate, scmark) values
437+
(1001, 1111, '2017-09-01', 95),
438+
(1001, 2222, '2017-09-01', 87.5),
439+
(1001, 3333, '2017-09-01', 100),
440+
(1001, 4444, '2018-09-03', null),
441+
(1001, 6666, '2017-09-02', 100),
442+
(1002, 1111, '2017-09-03', 65),
443+
(1002, 5555, '2017-09-01', 42),
444+
(1033, 1111, '2017-09-03', 92.5),
445+
(1033, 4444, '2017-09-01', 78),
446+
(1033, 5555, '2017-09-01', 82.5),
447+
(1572, 1111, '2017-09-02', 78),
448+
(1378, 1111, '2017-09-05', 82),
449+
(1378, 7777, '2017-09-02', 65.5),
450+
(2035, 7777, '2018-09-03', 88),
451+
(2035, 9999, curdate(), null),
452+
(3755, 1111, date(now()), null),
453+
(3755, 8888, date(now()), null),
454+
(3755, 9999, '2017-09-01', 92)</string>
333455
<string>select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 5 offset 10</string>
334456
<string>select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 10, 5</string>
335457
<string>select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 5, 5</string>
@@ -347,29 +469,11 @@ select stuname, couname, scmark from tb_student t1, tb_course t2, tb_score t3 wh
347469
<string>select stuname, avgmark from tb_student t1, (select stuid, avg(scmark) as avgmark from tb_score group by stuid) t2 where t1.stuid=t2.stuid</string>
348470
<string>select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid</string>
349471
<string>select stuname, ifnull(total,0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid</string>
350-
<string>-- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算)
351-
select stuname from tb_student where stuid=(
352-
select stuid from tb_score group by stuid having count(stuid)&gt;2
353-
)
354-
355-
-- 查询学生姓名、课程名称以及成绩(连接查询)
356-
357-
-- 查询选课学生的姓名和平均成绩(子查询和连接查询)
358-
359-
-- 外连接(outer join):左外连接 / 右外连接 / 全外连接
360-
-- 查询每个学生的姓名和选课数量(左外连接和子查询)
361-
select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid</string>
362-
<string>select stuname, total from tb_student t1 left outer join
363-
(select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid</string>
364-
<string>select stuname, total from tb_student t1 inner join
365-
(select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid</string>
366-
<string>select stuid, count(stuid) from tb_score group by stuid</string>
367-
<string>select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid</string>
368472
</array>
369473
<key>rdbms_type</key>
370474
<string>mysql</string>
371475
<key>rdbms_version</key>
372-
<string>5.5.60-MariaDB</string>
476+
<string>5.7.26</string>
373477
<key>version</key>
374478
<integer>1</integer>
375479
</dict>

Day36-40/关系型数据库MySQL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
);
402402
403403
-- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算)
404-
select stuname from tb_student where stuid=(
404+
select stuname from tb_student where stuid in (
405405
select stuid from tb_score group by stuid having count(stuid)>2
406406
)
407407

0 commit comments

Comments
 (0)