SQL经典练习题48道之二(11-19)

接上篇SQL经典练习题48道之一
11、查询“95031”班的学生人数。
答:
select COUNT(sno) from student where classnum=’95031’;
12、查询Score表中的最高分的学生学号和课程号。
答:
select sno,cno from score where degree =(select max(degree) from score);
13、查询‘3-105’号课程的平均分。
答:
select avg(degree) from score where cno=’3-105’;
14、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
答:
select cno,avg(degree) from score where cno in(select cno from score where cno like ‘3%’ group by cno having count(*)>4);
15、查询最低分大于70,最高分小于90的Sno列。
答:
select sno,max(degree),min(degree) from score group by sno having min(degree)>70 and max(degree)<90;
16、查询所有学生的Sname、Cno和Degree列。
答:
select sname,cno,degree from score s left join student st on s.sno=st.sno;
17、查询所有学生的Sno、Cname和Degree列。
答:
select sno,cname,degree from score s left join course c on s.cno=c.cno;
18、查询所有学生的Sname、Cname和Degree列。
答:
select sname,cname,degree from score s left join student st on s.sno=st.sno left join course c on s.cno=c.cno;
19、查询“95033”班所选课程的平均分。
答:
select avg(degree) from score where sno in(select sno from student where classnum=’95033’);

猜你喜欢

转载自blog.csdn.net/u014332200/article/details/80579246