小笨蛋学习
#第6章
#【例6.1】查询student表中所有学生的学号、姓名和专业。
#【例6.2】查询student表中所有列。
#【例6.3】查询student表中所有学生的学生的sno、sname、speciality,并将结果中各列的标题分别修改为学号, 姓名, 专业。
#【例6.4】设student1表的表结构和样本数据与student表相同,且已创建和插入数据;在student1表中,列出学号、学分和增加4分后的学分。
#【例6.5】查询student表中speciality列,消除结果中的重复行。
#【例6.6】查询student表中专业为计算机或性别为女的学生。
use stusys;
select * from student;
select * from student
where speciality='计算机' or ssex='女';
#【例6.7】查询score表成绩为92、95的记录。
use stusys;
select * from score
where grade in(92,95);
#【例6.8】查询student表中不在1998年出生的学生情况。
use stusys;
select * from student
where sbirthday not between '1998-01-01' and '1998-12-31';
#【例6.9】查询已选课但未参加考试的学生情况。
use stusys;
select * from score
where grade is null;
#【例6.10】查询student表中姓董的学生情况。
use stusys;
select * from student
where sname like '董%';
#【例6.11】查询含有“系统”或“数字”的所有课程名称。
use stusys;
select * from course
where cname regexp '系统|数字';
#【例6.12】求学生的总人数。
use stusys;
select count(*) as 总人数
from student;
#【例6.13】查询通信专业学生的总人数。
use stusys;
select count(*) as 总人数
from student
where speciality='通信';
#【例6.14】查询1201课程总分。
use stusys;
select sum(grade) as 课程1201总分
from score
where cno='1201';
#【例6.15】查询8001课程的最高分、最低分、平均成绩。
use stusys;
select max(grade) as 课程8001总分,min(grade) as 课程8001最低分,avg(grade) as 课程8001平均成绩
from score
where cno='8001';
#【例6.16】查询各门课程的最高分、最低分、平均成绩。
use stusys;
select cno as 课程号,max(grade) as 最高分,min(grade) as 最低分,avg(grade) as 平均成绩
from score
where not grade is null
group by cno;
#【例6.17】查询平均成绩在90分以上的学生的学号和平均成绩。
use stusys;
select cno as 学号,avg(grade) as 平均成绩
from score
group by sno
having avg(grade)>90;
#【例6.18】查询至少有5名学生选修且以8开头的课程号和平均分数。
use stusys;
select cno as 课程号,avg(grade) as 平均分数
from score
group by sno
having avg(grade)>90;
#【例6.19】将计算机专业的学生按出生时间降序排序。
use stusys;
select * from student
where speciality='计算机'
order by sbirthday desc;
#【例6.20】查询成绩表中成绩前3位学生的学号、课程号和成绩。
use stusys;
select sno, cno, grade
from score
order by grade desc
limit 0, 3;
#【例6.21】采用交叉连接查询教师和和讲课地点所有可能组合。
#【例6.22】查询每个学生选修课程的情况。
#【例6.23】查询选修了数据库系统课程且成绩在80分以上的学生情况。
#【例6.24】对例6.22进行自然连接查询。
#【例6.25】查询选修了“1201”课程的成绩高于学号为“191002”的成绩的学生姓名。
#【例6.26】采用左外连接查询教师任课情况。
#【例6.27】采用右外连接查询教师任课情况。
#【例6.28】查询选修了课程号为8001的课程的学生情况。
#【例6.29】查询选修某课程的学生人数多于4人的教师姓名。
#【例6.30】查询比所有通信专业学生年龄都小的学生。
#【例6.31】查询选修1004课程的学生姓名。
#【例6.32】查询性别为女及选修了课程号为4002的学生。
#(1)课本P122——第3题:设计性实验1-8
#(2)课本P116——第四题:应用题1-17
#注意:请同学们课外再把上面例题项目在课堂上已经操作的内容独立(不看书)再操作一遍,没有操作的对照课本运行,将过程截图写文案于CSDN。