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

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 CId
    from course
    where CName='数据库'
) 

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

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

delete
from sc
where CId in (
    select CId
    from(
        select CId
        from sc
        group by CId
        having count(CId) < 6
    ) temp
)

-- 不能在同一个表中 一边查找一边删除
-- 解决方法为:使用派生表

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

update employee
set Salary= Salary+1000
where Eid = (
    select Eid
    from orders
    group by Eid
    order by sum(QTY) desc
    limit 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 sno
    from sc
    group by sno
    having count(cno)>=2
)
and ssex = '女'

-- 审题!!!

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

select round(avg(年龄),1) 平均年龄
from (
    select sno,2050 - year(bday) 年龄
    from students
    where sno in (
        select sno    -- 1.选修这门课的学号
        from sc
        where 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 students
    where 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 stu
    where sname = N'张三'
)
-- and not sname = N'张三'
-- and sname <> N'张三'
and sname != N'张三'
-- MSSQL字符串赋值,需要在字符串前面加 N

http://www.kler.cn/news/313190.html

相关文章:

  • FPGA基本结构和简单原理
  • Mac下nvm无法安装node问题
  • 设计模式-行为型模式-命令模式
  • 001.从0开始实现线性回归(pytorch)
  • 【Docker】安装及使用
  • EmguCV学习笔记 C# 12.3 OCR
  • Vue vs React vs Angular 的区别和选择
  • 数据结构-2.9.双链表
  • 周末愉快!——周复盘
  • 深度学习-03 Pytorch
  • Android 空气质量刻度
  • CleanClip For Mac 強大的剪貼簿助手Paste替代工具 v2.2.1
  • 学习笔记——EffcientNetV2
  • React——点击事件函数调用问题
  • Gradio离线部署到内网,资源加载失败问题(Gradio离线部署问题解决方法)
  • docker搭建个人网盘,支持多种格式,还能画图,一键部署
  • Matlab可视化│常用绘图全家桶
  • HTTP中的301、302实现重定向
  • ActivityManagerService 分发广播(6)
  • Vue3:reactive丢失响应式,数据有更新但表单没有更新
  • gin配置swagger文档
  • 树与图的深度优先遍历(dfs的图论中的应用)
  • 【CPP】类与继承
  • [原创]全新安装最新版Delphi 12.2之前, 如何正确卸载旧版Delphi 12.1?
  • 谈对象第二弹: C++类和对象(中)
  • SQLiteHelper
  • Java:List<String> 转换List<BigDecimal> 并求和
  • Hadoop-MapReduce的 原理 | 块和片 | Shuffle 过程 | Combiner
  • go 战略
  • Observability:构建下一代托管接入服务