




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 -查询“1”课程比“2”课程成绩高的所有学生的学号select a.stuid from (select * from t_sc s where s.cid = 1) a, (select * from t_sc s where s.cid = 2) b where a.stuid = b.stuid and a.score b.score;-2、查询平均成绩大于80分的同学的学号和平均成绩;select stuid, avg(score) from t_sc group by stuid having avg(score)80;-3、查询所有同学的学号、姓名、选课数、总成绩;select s.stuid, , c.xks, c.zcj from t_student s left outer join (select stuid, count(cid) xks, sum(score) zcj from t_sc group by stuid) c on s.stuid = c.stuid;select s.stuid, , count(c.cid), sum(c.score) from t_student s left Outer join t_sc c on s.stuid = c.stuid group by s.stuid, ;-4、查询姓“李”的老师的个数;select count(tid) from t_teacher where tname like 李%;-5、查询没学过“叶平”老师课的同学的学号、姓名;select s.stuid, 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.teacherid=t.tid and t.tname!=叶平;-6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;select s.stuid, from t_student s, t_sc c where c.cid=1 and s.stuid=c.stuid and exists (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#=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.snamehaving count(sc.cid)=(select count(*) from teacher t,course c where t.tid=c.tid and t.tname=叶平);-8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;Select S#, Sname from (select Student.S#, Student.Sname, score, (select score from SC SC_2 where SC_2.S# = Student.S#and SC_2.C# = 002) score2 from Student, SC where Student.S# = SC.S# andC# = 001) S_2 where score2 score; -9、查询所有课程成绩小于60分的同学的学号、姓名;select s.sid,s.sname from student s ,sc c where c.sid=s.sid group by s.sid,s.sname having max(c.score)=60 and s.stuid=sc.stuid);select s.stuid, 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(c.cid)(select count(*) from course)select s.stuid, from t_student s,t_sc sc where s.stuid=sc.stuid group by s.stuid, having count(sc.cid) != (select count(cid) from t_course); select Student.S#, Student.Sname from Student, SC whereStudent.S# = SC.S# group by Student.S#, Student.Sname having count(C#) (select count(C#) from Course);-11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;select distinct s.sid from sc s where s.cid in(select c.cid from sc c where sid=1) and s.sid1select distinct s.stuid, 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, 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”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;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 sid 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号课的平均成绩;insert into t_sc select stuid, 5 cid, (select avg(score) from t_sc sc where sc.cid=2) score from 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 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) kcs from (select s.stuid, stuname, sc.cid, sc.score, cname from t_student s, t_sc sc, t_course c where s.stuid = sc.stuid and sc.cid = c.cid and in (Chinese, Math, English) t group by t.stuid order 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 name 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)|% jgl from t_sc sc group by sc.cid order by avgscore, jgl desc;-20、查询如下课程平均成绩和及格率的百分数(用1行显示): -企业管理(001),马克思(002),OO&UML (003),数据库(004) select * from t_sc sc group by sc.cidselect sc.cid, (select name from t_course where cid=sc.cid) cname, case sc.cid when 1 then round(avg(sc.score),2) end chinese_avgscore, case sc.cid when 1 then round(select count(*) from t_sc where cid = sc.cid and score=70)/ (select count(*) from t_sc where cid = sc.cid)*100,2)|% end chinese_jgl from t_sc sc group by sc.cid-21、查询不同老师所教不同课程平均分从高到低显示select sc.cid, round(avg(sc.score),2) avg_score, , t.tname from t_sc sc, t_course c, t_teacher t where sc.cid=c.cid and t.tid=c.teacherid group by sc.cid, , t.tname order by avg_score desc;-22、查询如下语文成绩第 2 名到第 5 名的学生成绩单:-学生ID,学生姓名,语文成绩, 排名select * from (select t.*, rownum tn from (select s.stuid, , min(case when Chinese then sc.score end) chinese_score from t_student s, t_sc sc, t_course c where s.stuid = sc.stuid and sc.cid = c.cid group by s.stuid, order by chinese_score desc) t where rownum 1 -23、统计列印各科成绩,各分数段人数:课程ID,课程名称,100-85,85-70,70-60, =85 and score=70 and score=60 and score70) c,(select count(*) from t_sc where cid=sc.cid and score60) d from t_sc sc, t_course c where sc.cid = c.cid group by sc.cid, ;-24、查询学生平均成绩及其名次 select t.*, rownum rn from (select s.stuid, , avg(sc.score) avg_score from t_student s, t_sc sc where s.stuid=sc.stuidgroup by s.stuid, order by avg_score desc) t;select t.*, row_number() over(order by avg_score desc) pm from (select s.stuid, , avg(sc.score) avg_score from t_student s, t_sc sc where s.stuid=sc.stuidgroup by s.stuid, ) t;-25、查询各科成绩前三名的记录:(不考虑成绩并列情况) select * from (select sc.cid, , sc.score, row_number() over(partition by sc.cid, order by sc.score desc) pmfrom t_sc sc, t_course c where sc.cid=c.cid ) where pm 1;-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;-33、查询平均成绩大于85的所有学生的学号、姓名和平均成绩 select s.stuid, , round(avg(sc.score), 2) avg_score from t_student s, t_sc sc where s.stuid=sc.stuid group by s.stuid, having avg(sc.score)80;-34、查询课程名称为“数据库”,且分数低于60的学生姓名和分数 select s.stuid, stuname, sc.score from t_student s, t_sc sc, t_course c where s.stuid=sc.stuid and sc.cid=c.cid and =Computer and sc.score70;-37、查询不及格的课程,并按课程号从大到小排列 select c.cid, from t_sc sc, t_course c where sc.cid=c.cid group by c.cid,,sc.score having sc.score80;-39、求选了课程的学生人数select count(*) rs from (select stuid from t_sc group by stuid);-40、查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩 select s.stuid, stuname, t.max_score from t_student s, t_sc sc,(select c.cid, max(sc.score) max_score from t_sc sc, t_course c, t_teacher t where sc.cid=c.cid and c.teacherid=t.tidand t.tname=Mr.mao group by c.cid) t where s.stuid=sc.stuid and sc.cid=t.cid and sc.score=t.max_score;-41、查询各个课程及相应的选修人数select cid, count(*) rs from t_sc group by cid order by cid;-42、查询不同课程成绩相同的学生的学号、课程号、学生成绩 select * from t_sc sc where exists (select * from t_sc where stuid!=sc.stuid and cid!=sc.cid and score=sc.score);select distinct A.Stuid,B.score from t_SC A ,t_SC B where A.Score=B.Score and A.Cid B.Cid ; -43、查询每门功成绩最好的前两名 select * from (select stuid, cid ,score, row_number() over(partition by cid order by score desc) pm from t_sc) where pm 5 order by rs desc, cid;-45、检索至少选修两门课程的学生学号 select stuid ,count(*) from t_sc group by stuid having count(*) 2;-46、查询全部学生都选修的课程的课程号和课程名 select c.cid, from t_course
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 政治安全题库高中及答案解析
- 2025年中国移动教室行业市场全景分析及前景机遇研判报告
- 2025年男科疾病诊断治疗规范考核答案及解析
- 2025年公务员考试时事政治测试卷附参考答案详解(精练)题型大全
- 2025年中共西林县委西林县人民政府接待办公室招聘编外聘用人员考前自测高频考点模拟试题及答案详解(各地真题)
- 浦发银行南宁市兴宁区2025秋招笔试综合模拟题库及答案
- 2025辅警招聘考试考前冲刺测试卷附参考答案详解(培优A卷)
- 浦发银行拉萨市城关区2025秋招笔试性格测试题专练及答案
- 2025年法律职业资格考试高频难、易错点题含答案详解【培优】
- 【论文-教育教学】农村小学“家校协同评价”机制的实践困境与对策
- 新能源汽车充电桩工程物资供应措施
- 基于大数据的国际广播媒体发展模式比较分析-洞察阐释
- DB32-T 5108-2025 科技服务机构星级评定规范
- JG/T 441-2014额定电压450/750 V及以下双层共挤绝缘辐照交联无卤低烟阻燃电线
- T/CI 311-2024风力发电机组高强钢塔架焊接附属件结构疲劳性能评价方法
- 公安计算机试题及答案
- 《肠道菌群》课件
- 《中医药信息学》课件
- 铁路旅客运输服务普速列车设备设施规范课件
- 大型活动标准化执行手册
- 做账实操-桌球俱乐部账务处理流程
评论
0/150
提交评论