已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
-表结构-学生表tblstudent(编号stuid、姓名stuname、年龄stuage、性别stusex)-课程表tblcourse(课程编号courseid、课程名称coursename、教师编号teaid)-成绩表tblscore(学生编号stuid、课程编号courseid、成绩score)-教师表tblteacher(教师编号teaid、姓名teaname)-1、查询“001”课程比“002”课程成绩高的所有学生的学号;select t1.stuid from (select stuid, score from tblscore where courseid = 001) t1, (select stuid, score from tblscore where courseid = 002) t2 where t1.stuid = t2.stuid and t1.score t2.score;-2、查询平均成绩大于60分的同学的学号和平均成绩; select stuid, avg(nvl(score, 0) from tblscore group by stuidhaving avg(nvl(score, 0) 60 order by stuid;-3、查询所有同学的学号、姓名、选课数、总成绩;select tblstudent.stuid, tblstudent.stuname, count(tblscore.courseid), sum(nvl(score, 0) from tblstudent left outer join tblscore on tblstudent.stuid = tblscore.stuid group by tblstudent.stuid, stuname;-4、查询姓“李”的老师的个数; select count(*) from tblteacher where teaname like 李%;-5、查询没学过“叶平”老师课的同学的学号、姓名;select s.stuid, s.stuname from tblstudent s where stuid not in (select stuid from tblscore where courseid in (select courseid from tblcourse where teaid = (select teaid from tblteacher where teaname = 叶平);-6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名; select s.stuid, s.stuname from tblstudent s, (select stuid from tblscore where courseid = 001) t1, (select stuid from tblscore where courseid = 002) t2 where t1.stuid = t2.stuid and s.stuid = t1.stuid;-7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;select stuid,stuname from tblstudent where stuid in (select tblscore.stuid from tblcourse left join tblscore on tblcourse.courseid = tblscore.courseid where tblcourse.teaid = (select teaid from tblteacher where teaname = 叶平) group by tblscore.stuid having count(*) = (select count(*) from tblcourse where teaid = (select teaid from tblteacher where teaname = 叶平); -8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名; select t1.stuid, t1.stuname from (select s.stuid, s.stuname, tblscore.score from tblstudent s left join tblscore on s.stuid = tblscore.stuid where courseid = 002) t1 left join (select s.stuid, s.stuname, tblscore.score from tblstudent s left join tblscore on s.stuid = tblscore.stuid where courseid = 001) t2 on t1.stuid = t2.stuid where t1. score 60);-10、查询没有学全所有课的同学的学号、姓名;select s.stuid, s.stuname from tblstudent s left join tblscore on s.stuid = tblscore.stuid group by s.stuid, s.stunamehaving count(tblscore.courseid) (select count(*) from tblcourse);-11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;select distinct s.stuid, s.stuname from tblstudent s left join tblscore on s.stuid = tblscore.stuid where tblscore.courseid in (select courseid from tblscore where stuid = 1001);-12、查询至少学过学号为“1001”同学所有课程的其他同学学号和姓名; select distinct s.stuid,s.stuname from tblstudent s left join tblscore on s.stuid = tblscore.stuid where tblscore.stuid 001 and tblscore.courseid in (select courseid from tblscore where stuid = 001);-13、把“sc”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; update tblscore sct set sct.score = (select avg(score) from tblscore sct2 where sct2.courseid = sct.courseid) where sct.courseid = (select c.courseid from tblcourse c, tblteacher t where c.courseid = sct.courseid and c.teaid = t.teaid and t.teaname = 叶平);-14、查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名; select stuid from tblscore where stuid != 1002 and courseid in (select courseid from tblscore where stuid = 1002) group by stuidhaving count(*) = (select count(*) from tblscore where stuid = 1002);-15、删除学习“叶平”老师课的sc表记录;delete from tblscore sct where sct.courseid in (select c.courseid from tblcourse c, tblscore sct2, tblteacher t where c.courseid = sct2.courseid and c.teaid = t.teaid and t.teaname = 叶平);-16、向sc表中插入一些记录,这些记录要求符合以下条件:没有上过编号“003”课程的同学学号、002号课的平均成绩; insert into tblscore (stuid, courseid, score) select s.stuid, 003, (select avg(score) from tblscore sct where sct.courseid = 002) from tblstudent s where s.stuid not in (select sct.stuid from tblscore sct where sct.courseid = 003);-17、按平均成绩从高到低显示所有学生的“数据库”、“企业管理”、“英语”三门的课程成绩,按如下形式显示: 学生id,数据库,企业管理,英语,有效课程数,有效平均分 select s.stuid, sum(case when sct.courseid = 数据库 then sct.score else 0 end) database, sum(case when sct.courseid = 企业管理 then sct.score else 0 end) enterprise, sum(case when sct.courseid = 英语 then sct.score else 0 end) english, (select avg(sct2.score) from tblscore sct2 where sct2.stuid = s.stuid) score from tblstudent s, tblscore sct where s.stuid = sct.stuid group by s.stuid order by score desc;-18、查询各科成绩最高和最低的分:以如下形式显示:课程id,最高分,最低分 select c.courseid, max(sct.score), min(sct.score) from tblscore sct, tblcourse c where c.courseid = sct.courseid group by c.courseid;-19、按各科平均成绩从低到高和及格率的百分数从高到低顺序 (百分数后如何格式化为两位小数?)select tblscore.courseid, avg(tblscore.score), (convert(varchar(10), (select count(*) from tblscore sc Where sc.courseid = cs.courseid and sc.score = 60) * 10000 / (select count(*) from tblscore sc Where sc.courseid = cs.courseid) / 100) + %) from tblscore cs as tmp group by 课程id, 平均分, 及格率order by 平均分, convert(float, substring(及格率, 1, len(及格率) - 1) desc;-20、查询如下课程平均成绩和及格率的百分数(用1行显示): 企业管理(001),马克思(002),oo¨ (003),数据库(004) select sct.courseid, avg(score), (select count(*) from tblscore sct2 where sct2.courseid = sct.courseid and sct2.score = 60) / (select count(*) from tblscore sct2 where sct2.courseid = sct.courseid) pass from tblscore sct where sct.courseid in (001, 002, 003, 004) group by sct.courseid order by pass desc;-21、查询不同老师所教不同课程平均分从高到低显示 select t.teaname, c.coursename, avg(sct.score) avgscore from tblteacher t, tblcourse c, tblscore sct where t.teaid = c.teaid and c.courseid = sct.courseid group by t.teaname, c.coursename order by avgscore desc;-22、查询如下课程成绩第 3 名到第 6 名的学生成绩单:企业管理(001),马克思(002),uml (003),数据库(004) 格式:学生id,学生姓名,企业管理,马克思,uml,数据库,平均成绩 select s.stuid,s.stuname,企业管理,马克思,v.uml, 数据库,v.avgscore from (select rownum id, s.stuid,s.stuname,v.mng 企业管理,v.mks 马克思,v.uml,v.db 数据库,v.avgscore from tblstudent s,(select s.stuid,sum(case when sct.courseid=001 then sct.score else 0 end) mng, sum(case when sct.courseid=002 then sct.score else 0 end) mks, sum(case when sct.courseid=003 then sct.score else 0 end) uml, sum(case when sct.courseid=004 then sct.score else 0 end) db, (sum(case when sct.courseid=001 then sct.score else 0 end) + sum(case when sct.courseid=002 then sct.score else 0 end) + sum(case when sct.courseid=003 then sct.score else 0 end) + sum(case when sct.courseid=004 then sct.scoreo else 0 end)/4 avgscorefrom sct s,tblscore sct where s.stuid=sct.stuid group by s.stuid) v where s.stuid=v.stuid order by avgscore desc) where id between 3 and 6;with s1 as (select t.stuid,t.courseid,t.score,t.rank from (select s2.*,rank() over(partition by courseid order by score desc) rankfrom tblscore s2 where courseid in(001,002,003,004)t where t.rank betWeen 3 and 6) ,s2 as (select stuid,sum(decode(courseid,001,score) cj1,sum(decode(courseid,002,score) cj2,sum(decode(courseid,003,score) cj3,sum(decode(courseid,004,score) cj4 from tblscore group by stuid) ,s3 as (select stuid,avg(nvl(score,0) avgs from tblscore group by stuid) select distinct s1.stuid,s4.stuname,s2.cj1,s2.cj2,s2.cj3,s2.cj4,s3.avgs from s1,s2,s3,tblstudent s4 where s1.stuid=s2.stuid and s1.stuid=s3.stuid and s1.stuid=s4.stuid;-23、统计列印各科成绩,各分数段人数:课程id,课程名称,100-85,85-70,70-60, 60 select c.courseid 课程id, c.coursename 课程名称, v.a 60, v.b 60-70, v.c 70-85, v.d 85-100 from tblcourse c, (select sct.courseid, sum(case when sct.score = 60 and sct.score = 70 and sct.score = 85 and sct.score 100 then 1 else 0 end) d from tblscore sct group by sct.courseid) v where c.courseid = v.courseid;-24、查询学生平均成绩及其名次 select s.stuid, s.stuname, v.avgscore, (select count(*) from (select sct.stuid, avg(sct.score) avgscore from tblscore sct group by sct.stuid) v2 where v.avgscore 1-31、1981年出生的学生名单(注:student表中sage列的类型是datetime) select stuname, stuage from tblstudent where to_char(sysdate, yyyy) - stuage = 1981;-32、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列 select courseid, avg(score) from tblscore group by courseid order by avg(score), courseid desc;-33、查询平均成绩大于85的所有学生的学号、姓名和平均成绩 select stuname, tblscore.stuid, avg(score) from tblstudent, tblscore where tblstudent.stuid = tblscore.stuid group by tblscore.stuid, stunamehaving avg(score) 85;-34、查询课程名称为“数据库”,且分数低于60的学生姓名和分数 select stuname, score from tblstudent, tblscore, tblcourse where tblscore.stuid = tblstudent.stuid and tblscore.courseid = tblcourse.courseid and tblcourse.coursename = 数据库 and score = 70 and tblscore.stuid = tblstudent.stuid and c.courseid = tblscore.courseid;-37、查询不及格的课程,并按课程号从大到小排列 select * from tblscore Where score 80 and courseid = 003;-39、求选了课程的学生人数 select count(distinct stuid) from tblscore;-40、查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩select tblstudent.stuname, score from tblstudent, tblscore, tblcourse, tblteacher where tblstudent.stuid = tblscore.stuid and tblscore.courseid = tblcourse.courseid and tblcourse.teaid = tblteacher.teaid and tblteacher.teaname = 叶平 and tblscore.score = (select max(score) from tblscore where courseid = tblcourse.courseid);-41、查询各个课程及相应的选修人数(有些课程可能没有人选)select count(distinct stuid) from tblscore group by courseid;-42、查询不同课程成绩相同的学生的学号、课程号、学生成绩 Select 学号 = StuId, 课程号 = CourseId, 成绩 = Score From tblScore sc Where Exists (Select * From tblScore Where Score = sc.Score And StuId = sc.StuId And CourseId sc.CourseId) Order by 学号, 成绩-43、查询每门功成绩最好的前两名 select tblcourseid, 第1名=(select top 1 stuid from tblscore where courseid=cs.courseid order by score desc), 第2名=(select top 1 stuid from (select top 2 stuid,score from tblscore where courseid=cs.courseid order by score desc) as tmp order by score) from tblcourse cs;-44、统计每门课程的学生选修人数(超过10人的课程
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年下半年吉林省通化市通化县事业单位专项招聘20人(5号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林省直事业单位招聘833人(2号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林省机构编制委员会所属事业单位公开招聘易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年吉林市县(市)区事业单位招聘入伍高校毕业生142人(3号)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年台州市仙居县委老干部局临时工招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年厦门理工学院现代工程训练中心招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年厦门市思明区文体出版局招考非编人员易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年南通平潮镇招考城管协管员易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年南宁市兴宁区政法委招考抢险救灾应急突击队员易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年北京市房山区属事业单位面向毕业生招聘122人笔试易考易错模拟试题(共500题)试卷后附参考答案
- 职业卫生技术服务专业技术人员考试(职业卫生评价)例题及答案(辽宁省凌源市2025年)
- 2025至2030细胞分离产物行业产业运行态势及投资规划深度研究报告
- 吉安市2025年度市直事业单位公开选调工作人员【70人】考试参考试题及答案解析
- DCS网络安全培训课件
- 2025年辽宁省辽阳市事业单位工勤技能考试题库及答案
- 认知功能康复训练
- 工厂盗窃安全培训内容课件
- DB32∕T 3823-2020 船闸PLC控制系统设计规范
- 四川省甘孜藏族自治州甘孜县2026届八年级物理第一学期期末教学质量检测试题含解析
- 护士医学院毕业论文
- 湖北农商行面试题目及答案
评论
0/150
提交评论