例题:从下边一个成绩表做出三个题,题目比较难理解

               

     

 

                     

33、查询成绩比该课程平均成绩低的同学的成绩表。

select*from score a where DEGREE <(select avg(degree) from score b where a.cno=b.cno )

 

-查询每门课最高分学生之外的其他学生分数信息

select*from score a where DEGREE not in(select MAX(degree) from score b where a.cno=b.cno)

a.cno=b.cno 这句代码的意思是在同一门课程中 选出最高分,where degree not in 就是把最高分去掉

--剔除选多门课的每门课最高分

select *from score a where DEGREE not in (select MAX(degree)from score b where a.cno=b.cno) and sno not in (select cno from score

 group by cno having COUNT(*)=1)

select cno from score group by cno having count(*)=1   --这句话表示把学生学一门课的课程都显示出来,前面加个not in 剩下的就是选多门课的课程

 

posted @ 2015-04-24 14:18  zhenximeiyitian  阅读(170)  评论(0编辑  收藏  举报