_学生选课数据库SQL语句练习题

1、 查询Student表中的所有记录的Sname、Ssex和Class列。

   select Sname,Ssex,t.sclass from STUDENT t

2、 查询教师所有的单位即不重复的Depart列。

   select distinct t.depart from TEACHER t

3、 查询Student表的所有记录。

   select * from STUDENT t

4、 查询Score表中成绩在60到80之间的所有记录。

select * from SCORE t where degree > 60 and degree < 80

5、 查询Score表中成绩为85,86或88的记录。

   select * from SCORE t where degree = 85 or degree = 86 or degree = 88

6、 查询Student表中“95031”班或性别为“女”的同学记录。

   select * from STUDENT t where t.sclass=9305 or t.ssex='女'

7、 以Class降序查询Student表的所有记录。

   select * from STUDENT t order by t.sclass desc

8、 以Cno升序、Degree降序查询Score表的所有记录。

   select * from SCORE t order by t.cno asc,t.degree desc

9、 查询“95031”班的学生人数。

   select count(*) from STUDENT t where t.sclass=95031

10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

11、 查询每门课的平均成绩。

   select avg(t.degree) from SCORE t group by t.cno   --分组

12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

   select t.cno,avg(t.degree) from SCORE t where t.cno like '3%' group by t.cno   --分组加在后面

13、查询分数大于70,小于90的Sno列。

   1select count(t.sno) from SCORE t where t.degree>60 or t.degree<90

   2select t.sno from SCORE t where t.degree between 60 and 90

   第一种为什么不行

14、查询所有学生的Sname、Cno和Degree列。

select c.sname,t.cno,t.degree from student c,score t where c.sno=t.sno

15、查询所有学生的Sno、Cname和Degree列。

select a.sno,b.cname,c.degree from student a,course b,score c where b.cno=c.cno and c.sno=a.sno

16、查询所有学生的Sname、Cname和Degree列。

 select a.sname,b.cname,c.degree from student a,course b, score c where a.sno=c.sno and b.cno=c.cno

17、 查询“95033”班学生的平均分。

select avg(degree) from student a,score b where a.class='95033' and b.sno=a.sno

20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。

   select t.sno from SCORE t where t.degree< (select max(t.degree) from SCORE t) group by sno having count(cno)>1

21、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。

   select * from score where cno='3-105' and degree>(select max(degree) from score where sno = '109' )

22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。

   select sno,sname,sbirthday from student t where t.sbirthday= (select sbirthday from student where sno='108')23、查询“张旭“教师任课的学生成绩。

25、查询95033班和95031班全体学生的记录。

   select * from STUDENT t,SCORE s where t.sclass=95033 or t.sclass=95031

原文地址:https://www.cnblogs.com/Levi1995/p/5962311.html