数据库实验——数据查询

3. 查询选修1号 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列;

select sno,grade

from sc

where cno='1'

order by grade desc,sno asc

6.查询缺少了成绩的学生的学号和课程号。

select sno,cno

from sc

where grade is null

7.查询每个学生的学号,姓名,选修的课程名,成绩;

select student.sno,sname,cname,grade

from student,course,sc

where student.sno=sc.sno and sc.cno=course.cno

10. 查询每门课程的先行课程的课程名称,学分;

select student.sno,sname,cname,grade

from student,course,sc

where student.sno=sc.sno and  sc.cno=course.cno

12.查询每一门课的间接先行课的课程名称;

select first.cno,second.cno,first.cname,second.cname

from course first,course second

where first.cpno=second.cno

13. 查询所在系部为“MA”且选修了高等数学课程的学生姓名,年龄,性别;

select student.sname,sage,ssex

from student,course

where sdept='MA' and cname='高等数学'

15. 查询选修了数据结构课程,且成绩在90分以上的学生姓名,年龄

select distinct sage,sname 

from SC,student 

where sc.grade>90 and cno='5' 

      andstudent.Sno=sc.Sno 

 

20.查询选修了全部课程的学生的姓名;

select Sname 

from  student 

where not exists 

     ( select * 

       fromCourse 

       where  not exists 

                (select * 

                 from sc 

                  where sno=student.Sno 

                         and cno=Course.Cno 

                         ) 

                          ) 

21.查询至少选修了学号为“201215121”的学生所选修的全部课程的学生学号和姓名;

select distinct sno 

from sc scx 

where not exists 

         ( select* 

           from scscy 

           wherescy.Sno='201215121' and 

                not exists 

                 (select * 

                   from sc scz 

                  where scz.sno=scx.sno and 

                  scz.Cno=scy.cno 

                  ) 

          ) 

25.查询选修了操作系统课程的学生人数;

select count(cno)

from sc

where cno='4'

29.查询选修了数据库课程的最高分,平均分;

select max(grade),avg(grade)

from sc,course

where sc.cno=course.cno and cname='数据库'

33.查询每个学生的学号,姓名,所获得的总学分(成绩大于等于60,则获得该门课程的学分);

SELECT sc.Sno,Sname,COUNT(Ccredit)

FROM student,course,sc

WHERE Grade>60 and student.Sno=sc.Sno andsc.Cno=course.Cno

GROUP BY sc.Sno,Sname

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章