学生成绩管理系统
山师数据库练习OJ: http://db.itoi.sd.cn/
数据库初始化:
1 | SET NAMES utf8mb4; |
基础30题:
- 查询全体学生的学号(Sno)与姓名(Sname)
1
2select Sno, Sname
from student - 查询全体学生的姓名(Sname)、学号(Sno)、所在系(Sdept)
1
2select sname, sno, sdept
from student - 查询全体学生的详细记录(Sno, Sname, Ssex, Sage, Sdept)
1
2select *
from student - 查询选修了课程的学生学号(Sno) (去除重复的学号)
1
2select distinct sno
from sc - 查询计算机科学系全体学生的名单(Sname)
1
2
3select sname
from student
where sdept = "CS" - 查询所有年龄在20岁以下的学生姓名(Sname)及其年龄(Sage)
1
2
3select sname, sage
from student
where sage < 20 - 查询考试成绩有不及格的学生的学号(Sno)
1
2
3select distinct sno
from sc
where grade < 60 - 查询年龄在20~23岁(包括20岁和23岁)之间的学生的姓名(Sname)、系别(Sdept)和年龄(Sage)
1
2
3select sname, sdept, sage
from student
where sage between 20 and 23 - 查询年龄不在20~23岁之间的学生姓名(Sname)、系别(Sdept)和年龄(Sage)
1
2
3select sname, sdept, sage
from student
where sage not between 20 and 23 - 查询计算机科学系(CS)、数学系(MA)和信息系(IS)学生的姓名(Sname)和性别(Ssex)
1
2
3select sname, ssex
from student
where sdept in ("CS", "MA", "IS"); - 查询既不是计算机科学系(CS)、数学系(MA),也不是信息系(IS)学生的姓名(Sname)和性别(Ssex)
1
2
3select sname, ssex
from student
where sdept not in ("CS","MA","IS"); - 查询所有姓刘学生的姓名(Sname)、学号(Sno)和性别(Ssex)
1
2
3select sname, sno, ssex
from student
where sname like "刘%" - 查询名字中第2个字为”立”字的学生的姓名(Sname)和学号(Sno)
1
2
3select sname, sno
from student
where sname like "%立%" - 查询所有不姓刘学生的姓名(Sname)、学号(Sno)和性别(Ssex)
1
2
3select sname, sno, ssex
from student
where sname not like "刘%" - 查询所有有成绩的学生学号(Sno)和课程号(Cno)
1
2
3select sno, cno
from sc
where grade is not null - 查询计算机系(CS)年龄在20岁以下的学生姓名(Sname)
1
2
3select sname
from student
where sage < 20 and sdept = "CS" - 查询选修了3号课程的学生的学号(Sno)及其成绩(Grade),查询结果按分数降序排列。
1
2
3select sno, grade
from sc
where cno = 3 order by grade desc - 查询全体学生情况(Sno, Sname, Ssex, Sage, Sdept),查询结果按所在系的系号升序排列,同一系中的学生按年龄降序排列
1
2
3select *
from student
order by sdept asc, sage desc - 查询学生总人数(COUNT)
1
2select count(*) as count
from student - 查询选修了课程的学生人数(查询列名为COUNT)
请使用AS指定列名1
2select count(distinct sno) as count
from sc - 计算1号课程的学生平均成绩(查询列名为AVG)
请使用AS指定列名1
2
3select avg(grade) as avg
from sc
where cno = 1 - 查询选修1号课程的学生最高分数(查询列名为MAX)
请使用AS指定列名1
2
3select max(grade) as max
from sc
where cno = 1; - 查询学生201215121选修课程的总学分数(查询列名为SUM)
请使用AS指定列名1
2
3select sum(ccredit) as sum
from course, sc
where sno = 201215121 and course.cno = sc.cno - 求各个有选课学生的课程号(Cno)及相应的选课人数(人数列名为COUNT)
请使用AS指定列名1
2
3select Cno, Count(*) as count
from SC
group by Cno - 查询选修了2门以上课程的学生学号(Sno)
1
2
3select sno
from sc
group by sno having count(*) > 2 - 查询平均成绩大于等于88分的学生学号(Sno)和平均成绩(平均成绩列名为AVG)
请使用AS指定列名1
2
3select sno, avg(grade) as avg
from sc
group by sno having avg(grade) >= 88 - 查询每个学生及其选修课程的情况(Sno, Sname, Ssex, Sage, Sdept, Cno, Grade)
1
2
3select student.*, cno, grade
from student, sc
where student.sno = sc.sno - 查询每一门课的间接先修课(即先修课的先修课)(Cno, Cpno)
1
2
3select x.cno, y.cpno
from course x, course y
where x.cpno = y.cno - 查询选修2号课程且成绩在80分以上的所有学生 (Sno, Sname)
1
2
3select student.sno, sname
from student left join sc on student.sno = sc.sno
where cno = 2 and grade > 80 - 查询每个选过课学生的学号(Sno)、姓名(Sname)、选修的课程名(Cname)及成绩(Grade)
1
2
3select student.sno, sname, cname, grade
from student, course, sc
where student.sno = sc.sno and sc.cno = course.cno