题15(3分):
查询年龄在20~23岁之间的学生的姓名,所在系和年龄。
select Sname,Sdept,Sage from student where Sage between 20 and 23;
题16(3分):
查询年龄不在20~23之间的学生的姓名,所在系和年龄。
select Sname,Sdept,Sage from student where Sage not between 20 and 23;
题17(3分):
查询信息系,数学系和计算机系学生的姓名和性别。
select Sname,Ssex from student where Sdept in ('信息系','数学系','计算机系');
题18(3分):
查询既不属于信息系,数学系,也不属于计算机系的学生的姓名和性别。
select Sname,Ssex from student where Sdept not in ('信息系','数学系','计算机系');
题19(3分):
查询姓“张”的学生的详细信息。
select * from student where Sname like '张%';
题20(3分):
查询学生表中姓“张”,姓“李”和姓“刘”的学生的情况。
select * from student where Sname like '张%' or Sname like '李%' or Sname like '刘%';
题21(3分):
查询名字中第2个字为“小”或“大”字的学生的姓名和学号。
select Sno, Sname from student where Sname like '_小%' or Sname like '_大%';
题22(3分):
查询所有不姓“刘”的学生。
select * from student where Sname not like '刘%' ;
题23(3分):
从学生表中查询学号的最后一位不是2,3,5的学生的情况。
select * from student where Sno not like '%2' or Sno not like '%3' or Sno not like '%5';
题24(3分):
查询无考试成绩的学生的学号和相应的课程号。
select Sno,Cno from sc where Grade is null ;
题25(3分):
查询所有有考试成绩的学生的学号和课程号。
select Sno,Cno from sc where Grade is not null ;
题26(3分):
查询计算机系年龄在20岁以下的学生的姓名。
select Sname from student where Sdept='计算机系' and Sage<20;
题27(3分):
将学生按年龄升序排序。
select * from student order by Sage asc;
题28(3分):
查询选修了课程“c02”的学生的学号及其成绩,查询结果按成绩降序排列。
select Sno,Grade from sc where Cno='C02' order by Grade desc;
题29(3分):
查询全体学生的信息,查询结果按所在系的系名升序排列,同一系的学生按年龄降序排列。
select * from student order by Sdept,Sage desc;
题39(3分):
查询每个学生的情况及其选课的情况。
select * from student left outer join sc on student.Sno=sc.Sno;
题41(3分):
查询计算机系学生的选课情况,要求列出学生的名字,所修课的课程号和成绩。
select Sname,Cno,Grade from student left outer join sc on student.Sno=sc.Sno where Sdept = '计算机系';
题42(3分):
查询信息系选修VB课程的学生的成绩,要求列出学生姓名,课程名和成绩。
select Sname,Cname,Grade from student join SC on student.Sno=sc.Sno join course on course.Cno=sc.Cno where Sdept = '信息系' and Cname = 'VB';
题43(3分):
查询所有选修了VB课程的学生的情况,要求列出学生姓名和所在的系。
select Sname,Sdept from student join SC on student.Sno=sc.Sno join course on course.Cno=sc.Cno where Cname = 'VB';
题44(3分):
查询与刘晨在同一个系学习的学生的姓名和所在系。
select Sname,Sdept from student where Sdept=(select Sdept from student where Sname='刘晨');
题45(4分):
查询学生的选课情况,包括选修课程的学生和没有修课的学生。
select * from student left join sc on student.Sno=sc.Sno;
题46(4分):
查询与刘晨在同一个系的学生。
select * from student where Sdept=(select Sdept from student where Sname='刘晨');
题47(4分):
查询成绩大于90分的学生的学号和姓名。
select Sno,Sname from student where Sno in (select Sno
from sc
where Grade>90);
题48(4分):
查询选修了“数据库基础”课程的学生的学号和姓名。
select Sno,Sname from student
where Sno in (select Sno
from sc
where Cno in (select Cno
from course
where Cname='数据库基础'));
题49(4分):
查询选修了课程“c02”且成绩高于次课程的平均成绩的学生的学号和成绩。
select Sno,Grade from sc
where Cno='c02' and Grade>(select avg(Grade)
from sc
where Cno='c02');
题50(4分):
查询选修了课程“c01”的学生姓名。
select Sname from student
where Sno in (select Sno
from sc
where Cno='c01');
题51(4分):
查询没有选修课程“c01”的学生姓名和所在系。
select Sname,Scept from student
where Sno not in (select Sno
from sc
where Cno='c01');
题52(4分):
查询选修了课程“c01”的学生的姓名和所在系。
select Sname,Scept from student
where Sno in (select Sno
from sc
where Cno='c01');
题53(4分):
查询数学系成绩在80分以上的学生的学号,姓名。
select student.Sno,Sname from student join sc on student.Sno=sc.Sno
where Sdept='数学系' and Grade>80;
题54(4分):
查询计算机系考试成绩最高的学生的姓名。
select Sname from student join sc on student.Sno=sc.Sno
where Sdept='计算机系' and Grade=(select max(Grade)
from student join sc on student.Sno=sc.Sno
Group by Sdept
having Sdept='计算机系');