數據庫實驗——數據查詢

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

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