--1.查询三张表的全部信息select*from student;select*from course;select*from sc;--2.查询全体学生的学号与姓名select sno, sname from student;--3.查询全体学生的姓名,学号和所在系select sname, sno, sdept from student;--4.查询全体学生的记录select*from student;--5.查询全体学生的姓名及其出生年份select sname,2021- sage from student;--6.查询全体学生的姓名和出生年份,并在出生年份列前加入一个列,此列的每行数据均为“Year of Birth”常量值select sname,'Year of Birth',2021- sage from student;--7.在选课表(SC)中查询有哪些学生选修了课程,并列出学生的学号selectdistinct sno from sc;--8.查询计算机系全体学生的姓名select sname from student where sdept ='计算机系';--9.查询所有年龄在20岁以下的学生的姓名及年龄select sname, sage from student where sage <20;--10.查询考试成绩不及格的学生的学号selectdistinct sno from sc where grade <60;--11.查询年龄在20~23岁之间的学生的姓名,所在系和年龄select sname, sdept, sage from student where sage between20and23;--12.查询年龄不在20~23之间的学生的姓名,所在系和年龄select sname, sdept, sage from student where sage notbetween20and23;--13.查询信息系,数学系和计算机系学生的姓名和性别select sname, ssex
from student
where sdept in('信息系','数学系','计算机系');--14.查询既不属于信息系,数学系,也不属于计算机系的学生的姓名和性别select sname, ssex
from student
where sdept notin('信息系','数学系','计算机系');--15.查询姓“张”的学生的详细信息select*from student where sname like'张%';--16.查询学生表中姓“张”,姓“李”和姓“刘”的学生的情况select*from student
where sname like'张%'or sname like'李%'or sname like'刘%';--17.查询名字中第2个字为“小”或“大”字的学生的姓名和学号select*from student
where sname like'_小%'or sname like'_大%';--18.查询所有不姓“刘”的学生select*from student where sname notlike'李%';--19.从学生表中查询学号的最后一位不是2,3,5的学生的情况select*from student
where sno notlike'%2'and sno notlike'%3'and sno notlike'%5';--20.查询无考试成绩的学生的学号和相应的课程号select sno, cno from sc where grade isnull;--21.查询所有有考试成绩的学生的学号和课程号select sno, cno from sc where grade isnotnull;--22.查询计算机系年龄在20岁以下的学生的姓名select sname
from student
where sdept ='计算机系'and sage <20;--23.将学生按年龄升序排序select*from student orderby sage;--24.查询选修了课程“c02”的学生的学号及其成绩,查询结果按成绩降序排列select sno, grade from sc where cno ='C02'orderby grade desc;--25.查询全体学生的信息,查询结果按所在系的系名升序排列,同一系的学生按年龄降序排列select*from student orderby sdept asc, sage desc;--26.统计学生总人数selectcount(1)from student;--27.统计选修了课程的学生的人数selectcount(distinct sno)from sc;--28.计算学号为9512101的学生的考试总成绩之和selectsum(grade)from sc groupby sno having sno ='9512101';--29.计算课程“c01”的学生的考试平均成绩selectavg(grade)from sc groupby cno having cno ='C01';--30.查询选修了课程“c01”的学生的最高分和最低分selectmax(grade),min(grade)from sc groupby cno having cno ='C01';--31.统计每门课程的选课人数,列出课程号和人数select cno,count(sno)from sc groupby cno;--32.查询每名学生的选课们数和平均成绩select sno,count(cno),avg(grade)from sc groupby sno;--33.查询选修了3门以上课程的学生的学号select sno,count(cno)from sc groupby sno havingcount(cno)>3;--34.查询选课门数等于或大于4门的学生的平均成绩和选课门数select sno,avg(grade),count(cno)from sc
groupby sno
havingcount(cno)>=4;--35.查询每个学生的情况及其选课的情况select s1.sno, s1.sname, s2.cno, s2.grade
from student s1
leftjoin sc s2
on s1.sno = s2.sno;--36.如果选课表中出现重复数据,需要对重复数据做处理deletefrom sc
where rowid notin(selectmax(rowid)from sc groupby sno, cno, grade, xklb);--37.查询计算机系学生的选课情况,要求列出学生的名字,所修课的课程号和成绩select sname, cno, grade
from(select*from student s1 leftjoin sc s2 on s1.sno = s2.sno)where sdept ='计算机系';--38.查询信息系选修VB课程的学生的成绩,要求列出学生姓名,课程名和成绩select sname, cname, grade
from(select*from student s1
join sc s2
on s1.sno = s2.sno
join course c
on s2.cno = c.cno)where cname ='VB';--39.查询所有选修了VB课程的学生的情况,要求列出学生姓名和所在的系select sname, sdept
from student
where sno in(select sno
from sc
where cno =(select cno from course where cname ='VB'));--40.查询与刘晨在同一个系学习的学生的姓名和所在系select sname, sdept
from student
where sdept =(select sdept from student where sname ='刘晨');--41.查询学生的选课情况,包括选修课程的学生和没有修课的学生select s1.sno, sname, cno
from student s1
leftjoin sc s2
on s1.sno = s2.sno;--42.查询与刘晨在同一个系的学生select*from student
where sdept =(select sdept from student where sname ='刘晨');--43.查询成绩大于90分的学生的学号和姓名select sno, sname
from student
where sno in(select sno from sc where grade >90);--44.查询选修了“数据库基础”课程的学生的学号和姓名select sno, sname
from student
where sno in(select sno
from sc
where cno =(select cno from course where cname ='数据库基础'));--45.查询选修了课程“c02”且成绩高于次课程的平均成绩的学生的学号和成绩select sno, grade
from sc
where cno ='C02'and grade >(selectavg(grade)from sc groupby cno having cno ='C02');--46.查询选修了课程“c01”的学生姓名select sname
from student
where sno in(select sno from sc where cno ='C01');--47.查询没有选修课程“c01”的学生姓名和所在系select sname
from student
where sno notin(select sno from sc where cno ='C01');--48.查询选修了课程“c01”的学生的姓名和所在系select sname, sdept
from student
where sno in(select sno from sc where cno ='C01');--49.查询数学系成绩在80分以上的学生的学号,姓名select sno, sname
from student
where sdept ='数学系'and sno in(select sno from sc where grade >80);--50.查询计算机系考试成绩最高的学生的姓名 select sname
from student
where sno =(select sno
from sc
where sno in(select sno from student where sdept ='计算机系')and grade =(selectmax(grade)from sc
where sno in(select sno from student where sdept ='计算机系')));--51.将新生纪录(9521105,陈冬,男,信息系,18岁)插入到Student表中insertinto student values('9521105','陈冬','男',18,'信息系');--52.在SC表中插入一新记录(9521105,c01),成绩暂缺insertinto sc values('9521105','C01',null,null);--53.将所有学生的年龄加1update student set sage = sage +1;--54.将“9512101”学生的年龄改为21岁update student set sage =21where sno ='9512101';--55.将计算机系学生的成绩加5分update sc
set grade = grade +1where sno in(select sno from student where sdept ='计算机系');--56.查询所有科目成绩中排名前三的学生姓名select sno, cno, grade, rownum
from(select sno, cno, grade
from sc
where grade isnotnullorderby grade desc)where rownum <=3;--56.查询所有科目成绩中排名第四到第六的学生姓名select sno, cno, grade
from(select sno, cno, grade, rownum num
from(select sno, cno, grade
from sc
where grade isnotnullorderby grade desc))where num between4and6;