1.分别查询学生表和学生修课表中的全部数据。
select * from student;
select * from course;
2.查询成绩在70到80分之间的学生的学号、课程号和成绩。
select sno as 学号,cno as 课程号 , grade as 成绩 from sc where grade between 70 and 80;
3.查询1号课程成绩最高的分数。
select max(grade) from sc where cno = 1;
4.查询学生都选修了哪些课程,要求列出课程号。
select cno 课程号,cname 课程 from course where cno in (select distinct cno from sc ) order by cno;
5.查询修了2号课程的所有学生的平均成绩、最高成绩和最低成绩。
select avg(grade) 平均成绩, max(grade) 最高成绩, min(grade) 最低成绩 from sc where cno = 2 ;
6.统计每个系的学生人数。
select sdet 系部,count(sname) 学生人数 from student group by sdet;
7.统计每门课程的修课人数和考试最高分。
select a.cname 课程,b.修课人数,b.最高分 from course a , (select cno,count(cno) 修课人数,max(grade) 最高分 from sc group by cno) b where a.cno = b.cno;
8.统计每个学生的选课门数,并按选课门数的递增顺序显示结果。
select b.sname,a.人数 from student b ,(select sno,count(sno) 人数 from sc group by sno ) a where a.sno =b.sno;
9.统计选修课的学生总数和考试的平均成绩.
select count(distinct sno) , round(avg(grade),2) from sc ;
10.查询选课门数超过2门的学生的平均成绩和选课门数。
select b.sname,a.科目数,a.平均分数 from student b ,(select sno,count(sno) 科目数 , avg(grade) 平均分数 from sc group by sno ) a where a.sno =b.sno;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载