27、1981 年出生的学生名单(注:Student 表中Sage 列的类型是number)
select * from student
where char(sysdate(),'yyyy')-sage =1981
28、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列
select cno,avg(score) from sc
group by cno
order by avg(score),cno desc;
29、查询平均成绩大于85 的所有学生的学号、姓名和平均成绩
select a.sno,a.sname,avg(b.score) from student a
join sc b on a.sno=b.sno
group by sno
having avg(score) >85;
30、查询课程名称为“数据库”,且分数低于60 的学生姓名和分数
#数据库应为Oracle
select a.sname,b.score from student a
join sc b on a.sno=b.sno
join course c on c.cno=b.cno and cname='Oracle'
and b.score < '60';
31、查询所有学生的选课情况;
select a.sno,a.sname,b.cno,c.cname from student a
join sc b on a.sno=b.sno
join course c on b.cno=c.cno;
32、查询任何一门课程成绩在70 分以上的姓名、课程名称和分数
select sname,cname,score from student a
join sc b on a.sno=b.sno
join course c on b.cno=c.cno
and b.score > 70;
33、查询不及格的课程,并按课程号从大到小排列
select a.sno,b.cname,a.score from sc a,course b
where a.cno=b.cno and a.score<60
order by a.cno desc;
34、查询课程编号为c001 且课程成绩在80 分以上的学生的学号和姓名
select a.sno,a.sname,b.score from student a
join sc b on a.sno=b.sno
and b.cno='c001' and b.score>80;
35、求选了课程的学生人数
select count(distinct sno) from sc
36、查询选修“谌燕”老师所授课程的学生中,成绩最高的学生姓名及其成绩
select sname,score from student a,course b,teacher c,sc d
where
a.sno=d.sno and b.tno=c.tno and b.cno=d.cno
and c.tname='谌燕' and d.score =
(select max(score) from sc where b.cno=sc.cno)
37、查询各个课程及相应的选修人数
select a.cno,a.cname,count(b.sno) from course a
join sc b on a.cno=b.cno
group by cno
38、查询不同课程成绩相同的学生的学号、课程号、学生成绩
select a.* from sc a,sc b
where a.score = b.score
and a.cno<>b.cno;
未解决 39、查询每门功课成绩最好的前两名
select * from (
select sno,cno,score,row_number()over(partition by cno order by score desc) my_rn from sc t
)
where my_rn<=2
40、统计每门课程的学生选修人数(超过10 人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列
select cno,count(sno) from sc
group by cno
having count(sno)>10
order by count(sno) desc,cno asc;
41、检索至少选修两门课程的学生学号
select sno from sc
group by sno
having count(sno)>=2
未解决 42、查询全部学生都选修的课程的课程号和课程名
43、查询没学过“谌燕”老师讲授的任一门课程的学生姓名
select distinct sname from student a
where a.sno not in (
select distinct c.sno from course a
join teacher b on a.tno=b.tno
join sc c on c.cno=a.cno
where b.tname='谌燕')
44、查询两门以上不及格课程的同学的学号及其平均成绩
select sno,avg(score) from sc
where sno in
(select sno from sc where sc.score<60
group by sno having count(sno)>1
) group by sno
45、检索“c004”课程分数小于60,按分数降序排列的同学学号
select sno,score from sc
where cno='c004' and score<60
order by sno desc;
46、删除“s002”同学的“c001”课程的成绩
delete from sc where sno='s002' and cno='c001';