完美的50sql题目及答案

上传人:tia****nde 文档编号:36868221 上传时间:2018-04-03 格式:DOCX 页数:8 大小:13.86KB
返回 下载 相关 举报
完美的50sql题目及答案_第1页
第1页 / 共8页
完美的50sql题目及答案_第2页
第2页 / 共8页
完美的50sql题目及答案_第3页
第3页 / 共8页
完美的50sql题目及答案_第4页
第4页 / 共8页
完美的50sql题目及答案_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《完美的50sql题目及答案》由会员分享,可在线阅读,更多相关《完美的50sql题目及答案(8页珍藏版)》请在金锄头文库上搜索。

1、Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 -查询“1”课程比“2”课程成绩高的所有学生的学号 select a.stuidfrom (select * from t_sc s where s.cid = 1) a,(select * from t_sc s where s.cid = 2) bwhere a.stuid = b.stuidand a.score b.score;-2、查询平均成绩大于 80 分的同学的学号和平均成绩; sele

2、ct stuid, avg(score) from t_sc group by stuid having avg(score)80;-3、查询所有同学的学号、姓名、选课数、总成绩; select s.stuid, s.name, c.xks, c.zcjfrom t_student s left outer join(select stuid, count(cid) xks, sum(score) zcjfrom t_scgroup by stuid) con s.stuid = c.stuid;select s.stuid, s.name, count(c.cid), sum(c.score

3、)from t_student sleft Outer join t_sc con s.stuid = c.stuidgroup by s.stuid, s.name;-4、查询姓“李”的老师的个数; select count(tid) from t_teacher where tname like 李%;-5、查询没学过“叶平”老师课的同学的学号、姓名; select s.stuid,s.name from t_student s, t_course c, t_teacher t, t_sc sc where s.stuid=sc.stuid and c.cid=sc.cid and c.t

4、eacherid=t.tid and t.tname!=叶平;-6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名; select s.stuid,s.name from t_student s, t_sc c where c.cid=1 and s.stuid=c.stuid andexists (select * from t_sc sc where sc.stuid=s.stuid and sc.cid=2);- select Student.S#,Student.Sname fromStudent,SC where Student.S#=SC.S# andSC.C#=

5、001and exists( Select * from SC as SC_2 where SC_2.S#=SC.S# and SC_2.C#=002);-7、查询学过“叶平”老师所教的所有课的同学的学号、姓名; select s.sid,s.sname from student s, sc sc where s.sid = sc.sid and sc.cid in( select c.cid from teacher t,course c where t.tid=c.tid and t.tname=叶 平) group by s.sid,s.sname having count(sc.cid

6、)=(select count(*) from teacher t,course c where t.tid=c.tid and t.tname=叶平);-8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、 姓名; Select S#, Snamefrom (select Student.S#,Student.Sname,score,(select scorefrom SC SC_2where SC_2.S# = Student.S#and SC_2.C# = 002) score2from Student, SCwhere Student.S# = SC.S# an

7、dC# = 001) S_2where score2 =60 and s.stuid=sc.stuid);select s.stuid, s.name from t_student s where not exists (select * from t_sc sc where sc.stuid=s.stuid and sc.score=60);-10、查询没有学全所有课的同学的学号、姓名;select s.sid from sc c,course e,student s where c.sid=s.sid and e.cid=c.sid group by s.sid having count(

8、c.cid) 1select distinct s.stuid,s.name from t_student s, t_sc sc where s.stuid=sc.stuid and s.stuid!=1 and sc.cid in (select cid from t_sc where stuid=1)-select s.stuid,s.name from t_Student s, t_SC sc where s.stuid=SC.Stuid and sc.cid in (select Cid from t_SC where stuid=1);-13、把“t_SC”表中“叶平”老师教的课的成

9、绩都更改为此课程的平均成绩;update t_sc sc1 set sc1.score = (select avg(score) from t_sc group by cid having cid in (select cid from t_teacher t, t_course c where t.tid=c.teacherid and t.tname=叶平) and cid=sc1.cid );-14、查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名; select sid from sc where sid in(select sid from sc group by s

10、id having count(*) =(select count(*) from sc where sid = 1) ) and cid in (select cid from sc where sid=1);-15、删除学习“叶平”老师课的 SC 表记录 delete t_sc where cid in( select cid from t_course c, t_teacher t where c.teacherid=t.tid and t.tname=Mr.mao);-16、向 SC 表中插入一些记录,这些记录要求符合以下条件:没有上过编号 “5”课程的同学学号、2 号课的平均成绩;

11、insert into t_sc select stuid, 5 cid, (select avg(score) from t_sc sc where sc.cid=2) scorefrom t_student s where not exists (select * from t_sc sc where sc.cid=5 and sc.stuid=s.stuid);-17、按平均成绩从高到低显示所有学生的“数据库” 、 “企业管理” 、 “英语”三 门的课程成绩,按 -如下形式显示: 学生 ID,数据库,企业管理,英语,有效课程数,有效平均分 select t.stuid,max(case

12、ame when Chinese then t.score end) Chinese,max(case ame when Math then t.score end) Math,max(case ame when English then t.score end) English,round(avg(t.score), 2) avgscore,count(t.cid) kcsfrom (select s.stuid, s.name stuname, sc.cid, sc.score, c.name cnamefrom t_student s, t_sc sc, t_course cwhere

13、s.stuid = sc.stuidand sc.cid = c.cidand c.name in (Chinese, Math, English) tgroup by t.stuidorder by avgscore desc;-18、查询各科成绩最高和最低的分:以如下形式显示:课程 ID,最高分,最 低分 select cid, max(score) maxscore, min(score) minscore from t_sc group by cid order by cid;-19、按各科平均成绩从低到高和及格率的百分数从高到低顺序 select sc.cid, (select na

14、me from t_course where cid=sc.cid) cname,round(avg(sc.score),2) avgscore,round(select count(*) from t_sc where cid = sc.cid and score=70)/(select count(*) from t_sc where cid = sc.cid)*100,2)|% jglfrom t_sc scgroup by sc.cidorder by avgscore, jgl desc;-20、查询如下课程平均成绩和及格率的百分数(用“1 行“显示): -企业管理(001) ,马克

15、思(002) ,OO-22、查询如下语文成绩第 2 名到第 5 名的学生成绩单: -学生 ID,学生姓名,语文成绩, 排名 select * from ( select t.*, rownum tn from ( select s.stuid, s.name,min(case c.name when Chinese then sc.score end) chinese_scorefrom t_student s, t_sc sc, t_course cwhere s.stuid = sc.stuidand sc.cid = c.cidgroup by s.stuid, s.nameorder

16、by chinese_score desc) t where rownum 1-23、统计列印各科成绩,各分数段人数:课程 ID,课程名称,100-85,85-70, 70-60, =85 and score=70 and score=60 and score1;-31、1981 年出生的学生名单(注:Student 表中 Sage 列的类型是 datetime) select to_char(sysdate,yyyy) year from dual;-32、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时, 按课程号降序排列 select cid, round(avg(score),2) avg_score from t_sc group by cid order by avg_score, cid desc;-

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号