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

server/2024/9/21 10:59:02/

练习题 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),显示班级名称、期末最高成绩

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

sql">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去重

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

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

sql">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表中信息学院学生所选修的课程号和成绩

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

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

sql">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门课程的女生姓名

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

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

sql">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表中所有学生的选课情况(包括学号,姓名,课号,成绩),结果中包括没有选课的学生

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

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

sql">-- 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”班的学生所选修的课程号

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

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

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

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

sql">-- 出生日期 大于所有女同学出生日期 的男同学 的姓名及系别
-- 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表中信息学院女学生的学生学号、姓名、课号及考试成绩。

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

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

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

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

sql">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)

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

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

sql">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

http://www.ppmy.cn/server/119788.html

相关文章

【深度学习|可视化】如何以图形化的方式展示神经网络的结构、训练过程、模型的中间状态或模型决策的结果??

【深度学习|可视化】如何以图形化的方式展示神经网络的结构、训练过程、模型的中间状态或模型决策的结果&#xff1f;&#xff1f; 【深度学习|可视化】如何以图形化的方式展示神经网络的结构、训练过程、模型的中间状态或模型决策的结果&#xff1f;&#xff1f; 文章目录 【…

2024/9/21 英语每日一段

“Girls mature earlier than boys,” she says. “They hit rapid growth at 11, 12, whereas boys hit it about 13. Once you hit ‘peak height velocity’, training should concentrate on the structural side, push strength and muscle development. Girls are missin…

【Javascript修炼篇】JS中的函数式编程

介绍&#xff1a; 函数式编程&#xff08;FP&#xff09;是一种编程范式&#xff0c;这意味着一种基于一些原则来思考软件构建的方法&#xff0c;比如 纯函数、不可变性、一等与高阶函数、函数组合、闭包、声明式编程、递归、引用透明性、柯里化 和 部分应用。 当这些原则有效…

k8s自动清理pod脚本分享

检查会遇到集群节点内存消耗超过90%&#xff0c;我们可以筛选一些可以进行重启的pods&#xff0c;如脚本中涉及svc-开头的&#xff0c;进行触发即重启的shell编写。此项会涉及metrics组件需要安装。 #!/bin/bash# 设置内存使用率阈值为90% MEMORY_THRESHOLD90# 初始化一个数组…

【Webpack--007】处理其他资源--视频音频

&#x1f913;&#x1f60d;Sam9029的CSDN博客主页:Sam9029的博客_CSDN博客-前端领域博主 &#x1f431;‍&#x1f409;若此文你认为写的不错&#xff0c;不要吝啬你的赞扬&#xff0c;求收藏&#xff0c;求评论&#xff0c;求一个大大的赞&#xff01;&#x1f44d;* &#x…

字符串函数的使用与模拟(2)——C语言内存函数

目录 1. memcpy函数的使用与模拟 2. memmove函数的使用与模拟 3. memset函数的使用 4. memcmp函数的使用 5. memchr函数的使用 前言&#xff1a;C语言内存函数是一组用于直接操作计算机内存的内置函数。使用时要包含头文件<string.h> 1. memcpy函数的使用与模拟 函…

opencv图像透视处理

引言 在图像处理与计算机视觉领域&#xff0c;透视变换&#xff08;Perspective Transformation&#xff09;是一种重要的图像校正技术&#xff0c;它允许我们根据图像中已知的四个点&#xff08;通常是矩形的四个角&#xff09;和目标位置的四个点&#xff0c;将图像从一个视…

LocalDateTime,OffsetDateTime和ZonedDateTime(上)

图片来源&#xff1a;https://www.cnblogs.com/yourbatman/p/14324575.html 一. LocalDate和LocalTime LocalDate&#xff1a;代表不含时区信息的日期&#xff0c;它只能表示年、月、日。它适用于记录一个日子&#xff0c;比如生日、纪念日、或者任何只需要日期而不需要具体时…