SQL经典练习题48道之五(31-35)

接上篇 SQL经典练习题48道之四(25-30)
31、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
答:
select cno,sno,degree from score where cno=’3-105’ and degree>=(select MAX(degree) from score where cno=’3-245’) order by degree desc;
32、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cname、Sname和Degree.
答:
select cname,sname,degree from (select cno,sno,degree from score where cno=’3-105’ and degree>(select MAX(degree) from score where cno=’3-245’)) s1 left join course c on s1.cno=c.cno left join student s2 on s1.sno =s2.sno;
33、查询所有教师和同学的name、sex和birthday.
答:
select sname name,ssex sex,sbirthday birthday from student union select tname name,tsex sex,tbirthday birthday from teacher;
34、查询所有“女”教师和“女”同学的name、sex和birthday.
答:
select * from (select sname name,ssex sex,sbirthday birthday from student union select tname name,tsex sex,tbirthday birthday from teacher)s where s.sex=’女’;
35、查询成绩比该课程平均成绩低的同学的成绩表
答:
select s1.* from score s1 inner join (select avg(degree) avgd,cno from score group by cno) s2 on s1.cno=s2.cno and s1.degree

猜你喜欢

转载自blog.csdn.net/u014332200/article/details/80584414
今日推荐