当前位置: 首页 > news >正文

SQL编程题复习(24/9/20)

练习题 x25

  • 10-120 统计每个班级期末成绩的最高分(Max),显示班级名称、期末最高成绩
  • 10-121 显示没有班导师的班级名称、院系名称
  • 10-122 将电子信息1班(班级编号:08)的班主任编号改为李丽清老师的编号(`PTA题目表述错误`)
  • 10-123 删除所有选修了"数据库"课程的选课记录
  • 10-124 删除选修人数小于6的选课记录(`建议二刷`)
  • 10-125 给订单量最多的员工,加薪1000元(`通过一半`)
  • 10-126 检索没被学生选修的课程编号和课程名称
  • 10-127 统计学校已开设的课程门数
  • 10-128 检索出students表、sc表和course表中"李小鹏"同学所选课程名称
  • 10-129 检索出teacher、teaching、course表中“王珊”老师所授课程的课程名称(`distinct去重`)
  • 10-130 检索出teachers、teaching、sc表中“谭浩强”教师任课的课程号,选修其课程的学生的学号和成绩(`建议二刷`)
  • 10-131 检索出students表和sc表中信息学院学生所选修的课程号和成绩
  • 10-132 检索出teachers表、teaching表和course表中女教师所授课程的课程号和课程名称(`distinct去重`)
  • 10-133 检索出students表、sc表中至少选修2门课程的女生姓名
  • 10-134 检索出students表、sc表中选修“0000011”课程的学生至2050年时平均年龄,要求结果中列名显示“平均年龄”(`不会`)
  • 10-135 检索出students表和sc表中所有学生的选课情况(包括学号,姓名,课号,成绩),结果中包括没有选课的学生
  • 10-136 检索出students表和sc表中没有选课的学生学号和姓名
  • 10-137 检索出students表和sc表中“19信管2”班的学生所选修的课程号
  • 10-138 检索出students表和sc表中“陈晓东”同学所选课程的课号及成绩
  • 10-139 检索出students表中出生日期大于所有女同学出生日期的男同学的姓名及系别
  • 10-140 检索出students表、sc表中信息学院女学生的学生学号、姓名、课号及考试成绩。
  • 10-141 检索出students表、sc表中“陈红”同学所选课程的成绩,列出课号和成绩(不考虑重名)
  • 10-142 检索出teachers 、teaching、course表中“王珊”老师所授课程的课程名称(`distinct去重`)
  • 10-143 查询所授每门课程平均成绩均在70分以上的教师(MSSQL)
  • 10-144 检索Student表中与‘张三’在同一个专业的学生记录(`MSSQL字符匹配`)

10-120 统计每个班级期末成绩的最高分(Max),显示班级名称、期末最高成绩

-- 统计每个班级 期末成绩的最高分
select GName,max(SCScore3) Max
from student,sc,grade
where student.SId=sc.SId
and student.GId=grade.GId
group by GName-- 依据输出样例分析 需要的表
-- 多表连接、等值连接

10-121 显示没有班导师的班级名称、院系名称

select GName,DName
from grade
left join dept on grade.DId=dept.DId
where TId <=> null-- 筛选符合输出样例的表
-- 以grade表为主,若TId为空则表示没有班导师

10-122 将电子信息1班(班级编号:08)的班主任编号改为李丽清老师的编号(PTA题目表述错误

update grade
set TId=(select TId from teacher where TName='李丽青')
where GId = '08'
and GName = '电子信息1班'

10-123 删除所有选修了"数据库"课程的选课记录

delete
from sc
where CId in (select CIdfrom coursewhere CName='数据库'
) -- 删除所有选修了"数据库"课程的 选课记录

10-124 删除选修人数小于6的选课记录(建议二刷

delete
from sc
where CId in (select CIdfrom(select CIdfrom scgroup by CIdhaving count(CId) < 6) temp
)-- 不能在同一个表中 一边查找一边删除
-- 解决方法为:使用派生表

10-125 给订单量最多的员工,加薪1000元(通过一半

update employee
set Salary= Salary+1000
where Eid = (select Eidfrom ordersgroup by Eidorder by sum(QTY) desclimit 1
)-- 做不会

10-126 检索没被学生选修的课程编号和课程名称

select course.cno,cname
from course 
left join score on course.cno=score.cno
where sno <=> null-- 避免 ambiguous 错误
-- 以course表为基准,sno为空则无人选择

10-127 统计学校已开设的课程门数

select count(*) 开设课程数
from course

10-128 检索出students表、sc表和course表中"李小鹏"同学所选课程名称

select distinct cname
from students,sc,course
where students.sno=sc.sno
and course.cno=sc.cno
and sname='李小鹏'

10-129 检索出teacher、teaching、course表中“王珊”老师所授课程的课程名称(distinct去重

select distinct cname
from teachers,teaching,course
where teachers.tno=teaching.tno
and teaching.cno=course.cno
and tname='王珊'-- 万能去重!!!

10-130 检索出teachers、teaching、sc表中“谭浩强”教师任课的课程号,选修其课程的学生的学号和成绩(建议二刷

select sc.cno,sno,score
from teachers,teaching,sc
where teachers.tno=teaching.tno
and teaching.cno=sc.cno
and tname='谭浩强'-- 建议二刷

10-131 检索出students表和sc表中信息学院学生所选修的课程号和成绩

select cno,score
from students,sc
where students.sno=sc.sno
and sdept='信息学院'

10-132 检索出teachers表、teaching表和course表中女教师所授课程的课程号和课程名称(distinct去重

select distinct course.cno,cname
from teachers,teaching,course
where teachers.tno=teaching.tno
and teaching.cno=course.cno
and tsex='女'-- distinct 去重!!!

10-133 检索出students表、sc表中至少选修2门课程的女生姓名

select sname 
from students
where sno in(select snofrom scgroup by snohaving count(cno)>=2
)
and ssex = '女'-- 审题!!!

10-134 检索出students表、sc表中选修“0000011”课程的学生至2050年时平均年龄,要求结果中列名显示“平均年龄”(不会

select round(avg(年龄),1) 平均年龄
from (select sno,2050 - year(bday) 年龄from studentswhere sno in (select sno    -- 1.选修这门课的学号from scwhere cno='0000011')
) temp-- 不会

10-135 检索出students表和sc表中所有学生的选课情况(包括学号,姓名,课号,成绩),结果中包括没有选课的学生

select students.sno,sname,cno,score
from students
left join sc on students.sno=sc.sno-- 将students 作为主表

10-136 检索出students表和sc表中没有选课的学生学号和姓名

-- select sno,sname
-- from students
-- where sno not in (
--     select sno -- 1.查询选了课的学生
--     from sc
-- )-- 没有选课的学生select students.sno,sname
from students
left join sc on students.sno=sc.sno
where cno <=> null-- 将students表作为主表连接,cno = null为没有选课

10-137 检索出students表和sc表中“19信管2”班的学生所选修的课程号

select cno
from students,sc
where students.sno=sc.sno
and class='19信管2'

10-138 检索出students表和sc表中“陈晓东”同学所选课程的课号及成绩

select cno,score
from students,sc
where students.sno=sc.sno
and sname='陈晓东'

10-139 检索出students表中出生日期大于所有女同学出生日期的男同学的姓名及系别

-- 出生日期 大于所有女同学出生日期 的男同学 的姓名及系别
-- select distinct sname,sdept
-- from students
-- where bday > all(
--     select bday
--     from students
--     where ssex='女'
-- )
-- and ssex='男'select sname,sdept
from students
where bday > (select max(bday)from studentswhere ssex='女'
)
and ssex='男'-- 大于所有 或者 比最大的都大

10-140 检索出students表、sc表中信息学院女学生的学生学号、姓名、课号及考试成绩。

select sc.sno,sname,cno,score
from students,sc
where students.sno=sc.sno
and sdept='信息学院' 
and ssex='女'

10-141 检索出students表、sc表中“陈红”同学所选课程的成绩,列出课号和成绩(不考虑重名)

select cno,score
from students
join sc on students.sno=sc.sno
where sname = '陈红'

10-142 检索出teachers 、teaching、course表中“王珊”老师所授课程的课程名称(distinct去重

select distinct cname
from teachers
join teaching on teachers.tno=teaching.tno
join course on teaching.cno=course.cno
where tname='王珊'-- distinct !!!

10-143 查询所授每门课程平均成绩均在70分以上的教师(MSSQL)

select CNO cno
from sc
group by CNO
having avg(GRADE)>70-- 1.先处理sc表
-- 平均成绩大于70的cno

10-144 检索Student表中与‘张三’在同一个专业的学生记录(MSSQL字符匹配)

select distinct sno 学号,sname 姓名
from stu
where mno in(select mno-- 1.查询张三的专业from stuwhere sname = N'张三'
)
-- and not sname = N'张三'
-- and sname <> N'张三'
and sname != N'张三'
-- MSSQL字符串赋值,需要在字符串前面加 N

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【随手笔记】使用J-LINK读写芯片内存数据
  • Java:List<String> 转换List<BigDecimal> 并求和
  • 【系统架构设计师】专业英语90题(附答案详解)
  • 手写Spring
  • 0基础跟德姆(dom)一起学AI 数据处理和统计分析04-Panda入门
  • ArrayList和Array有什么区别?
  • 【RabbitMQ 项目】项目概述
  • 9.20-使用k8s部署wordpress项目
  • ELF文件结构
  • Git入门学习(1)
  • 基于协同过滤算法+PHP的新闻推荐系统
  • 详解Linux中cat命令
  • linux-安全管理-防火墙与网络安全
  • 硬件工程师笔试面试——开关
  • 【网络安全的神秘世界】攻防环境搭建及漏洞原理学习
  • @jsonView过滤属性
  • 《Java编程思想》读书笔记-对象导论
  • Babel配置的不完全指南
  • css系列之关于字体的事
  • iOS | NSProxy
  • JavaScript 基础知识 - 入门篇(一)
  • javascript面向对象之创建对象
  • markdown编辑器简评
  • Python 反序列化安全问题(二)
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • 阿里研究院入选中国企业智库系统影响力榜
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 前端知识点整理(待续)
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 删除表内多余的重复数据
  • 使用SAX解析XML
  • puppet连载22:define用法
  • 阿里云ACE认证之理解CDN技术
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • !!java web学习笔记(一到五)
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • # 职场生活之道:善于团结
  • $.each()与$(selector).each()
  • $var=htmlencode(“‘);alert(‘2“); 的个人理解
  • (23)Linux的软硬连接
  • (Git) gitignore基础使用
  • (安卓)跳转应用市场APP详情页的方式
  • (备忘)Java Map 遍历
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • (九)One-Wire总线-DS18B20
  • (十二)python网络爬虫(理论+实战)——实战:使用BeautfulSoup解析baidu热搜新闻数据
  • (十二)springboot实战——SSE服务推送事件案例实现
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • *Django中的Ajax 纯js的书写样式1
  • .bashrc在哪里,alias妙用
  • .NET Core SkiaSharp 替代 System.Drawing.Common 的一些用法
  • .NET Core跨平台微服务学习资源
  • .Net 高效开发之不可错过的实用工具
  • .NET 药厂业务系统 CPU爆高分析
  • .Net--CLS,CTS,CLI,BCL,FCL