20_学生选课数据库SQL语句练习题1
25、查询95033班和95031班全体学生的记录。
select * from STUDENT t,SCORE s where t.sclass=95033 or t.sclass=95031
26、 查询存在有85分以上成绩的课程Cno.
select s.cno from SCORE s where s.degree>85
27、查询出“计算机系“教师所教课程的成绩表。
28、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
select tname,prof from teacher where prof not in
(
select a.prof from
(select prof from teacher where depart='电子工程系') a
join
(select prof from teacher where depart ='计算机系') b
on a.prof =b.prof ) and depart in ('计算机系','电子工程系')
29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
select t.degree from SCORE t where t.cno='3-105' and t.degree>(select min(t.degree) from SCORE t where t.cno='3-245')
30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.
select t.degree from SCORE t where t.cno='3-105' and t.degree> any (select t.degree from SCORE t where t.cno='3-245') order by t.degree desc;
31、 查询所有教师和同学的name、sex和birthday.
select tname,tsex,t.tbirthday from teacher t '
union
select sname,ssex,s.sbirthday from student s ';
32、查询所有“女”教师和“女”同学的name、sex和birthday.
select tname,tsex,t.tbirthday from teacher t where t.tsex='女'
union
select sname,ssex,s.sbirthday from student s where s.ssex='女';
33、 查询成绩比该课程平均成绩低的同学的成绩表。
34、 查询所有任课教师的Tname和Depart.
select tname,depart from teacher t where t.tno in
(select tno from course c where c.cno in(select cno from score))
35 、 查询所有未讲课的教师的Tname和Depart.
select tname,depart from teacher t where t.tno not in
(select tno from course c where c.cno in(select cno from score))
36、查询至少有2名男生的班号。
37、查询Student表中不姓“王”的同学记录。
38、查询Student表中每个学生的姓名和年龄。
38 select s.sname,to_char(sysdate,'yyyy')-to_char(s.sbirthday,'yyyy') from student s where s.sbirthday is not null
39、查询Student表中最大和最小的Sbirthday日期值。
39 select max(to_char(s.sbirthday,'mm/dd')),min(to_char(s.sbirthday,'mm/dd')) from student s
40、以班号和年龄从大到小的顺序查询Student表中的全部记录。
40 select s.* from student s where s.sbirthday is not null order by s.class,to_char(sysdate,'yyyy')
41、查询“男”教师及其所上的课程。
41 select c.tno,c.cno from course c inner join teacher t on t.tno=c.tno where t.tsex='男'
42、查询最高分同学的Sno、Cno和Degree列。
42 select s.sno,s.cno,s.degree from score s where degree=(select max(degree) from score)
43、查询和“李军”同性别的所有同学的Sname.
43 select s.sname from student s where s.ssex in (select ssex from student where ssex='男')
44、查询和“李军”同性别并同班的同学Sname.
44 select s.sname from student s where s.ssex in (select ssex from student where ssex='男') and s.class in
(select class from student where sname='李军')
45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
45 select s.* from score s inner join course c on c.cno=s.cno inner join student ss on ss.sno=s.sno
where ss.ssex='男' and c.cname='计算机导论'