查询Student表中的所有记录的Sname、Ssex和Class列。
select sname ,sex,sclass from student;
查询教师所有的单位即不重复的Depart列。
select distinct t.depart from teacher t;
查询Student表的所有记录
select * from student;
查询Score表中成绩在60到80之间的所有记录。
select * from score sc where degree between 60 and 80;
select * from score sc where degree >= 60 and degree <= 80;
查询Score表中成绩为85,86或88的记录。
select * from score where degree in (85,86,88);
select * from score where degree = '85' or degree ='86'or degree = '88');
查询Student表中“95031”班或性别为“女”的同学记录
select * from student where sclass ='95031' and ssex= '女';
以Class降序查询Student表的所有记录。
select * from student order by sclass desc;
以Cno升序、Degree降序查询Score表的所有记录
select * from score sc order by sc.sno asc ,sc.degree desc;
查询“95031”班的学生人数。
select s.sclass 总人数 from student s where sclass = '95031';
查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
select sc.sno,sc.cno from score sc order by degree desc;
查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select cno, avg(degree) from score where cno like '3%' group by cno having count(1)>=5 ;
查询所有学生的Sname、Cno和Degree列
select s.sname,sc.cno,sc.degree from score sc,student s where sc.sno=s.sno;
查询所有学生的Sno、Cname和Degree列
select s.sno,t.degree,c.cname from score sc,student s,course c where sc.sno=s.sno and sc.cno =c.cno;
查询所有学生的Sname、Cname和Degree列
select s.sname,t.degree,c.cname from score t,student s,course c where t.sno=s.sno and t.cno =c.cno;
查询“张旭“教师任课的学生成绩。
select t.tno,c.cno,c.cname,s.degree from TEACHER t join course c on t.tno =c.tno join score s on c.cno =s.cno where t.tname='张旭';
查询选修某课程的同学人数多于5人的教师姓名。
select tname from teacher e join course c on e.tno=c.tno join(select cno from SCORE group by cno having count(cno)>5) t on c.cno=t.cno ;
查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
select sno,sname,sbirthday from student where to_char(sbirthday,'yyyy')=(select to_char(t.sbirthday,'yyyy') from STUDENT t where sno='108')
查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
select cno from SCORE t where degree>85 group by cno
查询出“计算机系“教师所教课程的成绩表
select t.sno,t.cno,t.degree from SCORE t join course c on t.cno=c.cno join teacher e on c.tno=e.tno where e.depart ='计算机系';
查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof
select tname,prof from teacher where depart ='电子工程系' and prof not in(select prof from teacher where depart ='计算机系') or depart ='计算机系' and prof not in(select prof from teacher where depart='电子工程系');
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 )