第五章作业
1、查询学生选课表中的全部数据
select * from sc
2、查询计算机系学生的姓名、年龄
select sname,sage from student
where sdept=‘计算机系‘
3、查询成绩在70-80的学生的学号、课程号和成绩
select * from sc where grade between 70 to 80
4、查询计算机系年龄在18-20的男生的姓名、年龄
select sname,sage from student
Where sdept=’计算机系’ and sage between 18 to 20 and ssex=‘男’
5、查询“C01”课程的最高成绩
Select max(grade) from sc where cno=‘c01’
1
整理版课件
6、查询计算机系学生的最大年龄和最小年龄
select max(sage),min(sage) from student
where sdept=‘计算机系’
7、统计每个系的学生人数
select sdept,count(*) from student group by sdept
8、统计每门课程的选课人数和考试最高分
select cno,count(*),max(grade) from sc group by cno
9、统计每个学生的选课门数和考试总成绩,并按选课门数升序显示结果
select sno,count(*),sum(grade) from sc
group by sno order by count(*) asc
10、查询总成绩超过200分的学生,要求列出学号、总成绩
select sno,sum(grade) from sc
group by sno having sum(grade)>200
2
整理版课件
11、查询选修了”C02“课程的学生的姓名和所在系
select sname,sdept from student s join sc on = where =‘c02’
12、查询成绩80分以上的学生的姓名、选的课程号和成绩,并按成绩降序排列结果
select sname,cno,grade from student s join sc
on = where grade >80 order by grade desc
13、查询哪些学生没有选课,要求列出学号、姓名和所在系
select ,sname,sdept from student s left join sc on
= where is null
3
整理版课件
14、查询与VB在同一学期开设的课程的课程名和开课学期
select , from course c1 join course c2 on = where =‘VB’and !=‘VB’
15、查询与李勇年龄相同的学生的姓名、所在系和年龄
select ,, from student s1 join student s2 on = where =‘李勇’ and !=‘李勇’
4
整理版课件
16、查询计算机系年龄最小的2名学生的姓名和年龄
select top 2 with ties sname,sage from student where sdept=‘计算机系’order by sage asc
17、查询VB考试成绩最高的前2名学生的姓名、所在系和VB成绩,包括并列的情况
select top 2 with ties sname,sdept,grade from student s join sc on = join course c on = where cname=‘VB’ order by grade desc
18、查询选课门数最多的前2名学生的学号和选课门数,包括并列的情况
select top 2 with ties sno,count(*) from sc
group by sno order by count(*) desc
19、查询学生人数最多的系,列出系名和人数。
select top 1 sdept,count(*) fr
数据库第五六七章作业答案ppt课件 来自淘豆网www.taodocs.com转载请标明出处.