数据库二十一练习题

create table class
(
classid int primary key,
classname varchar(20)
)
insert into class values(1,‘G1T01’);
insert into class values(2,‘G1T02’);
insert into class values(3,‘G1T03’);
insert into class values(4,‘G1T04’);
insert into class values(5,‘G1T05’);
insert into class values(6,‘G1T06’);
insert into class values(7,‘G1T07’);
create table student
(
studentid varchar(20) primary key,
studentname varchar(20),
studentage int,
studentsex char(10),
studentaddress varchar(50),
classid int references class(classid)
)
insert into student values(‘2010001’,‘Jack’,21,‘男’,‘湖北襄樊’,1);
insert into student values(‘2010002’,‘Scott’,22,‘男’,‘湖北武汉’,2);
insert into student values(‘2010003’,‘Lucy’,23,‘女’,‘湖北武汉’,3);
insert into student values(‘2010004’,‘Alan’,19,‘女’,‘湖北襄樊’,4);
insert into student values(‘2010005’,‘Bill’,20,‘男’,‘湖北襄樊’,5);
insert into student values(‘2010006’,‘Bob’,21,‘男’,‘湖北宜昌’,6);
insert into student values(‘2010007’,‘Colin’,22,‘女’,‘湖北襄樊’,6);
insert into student values(‘2010008’,‘Fred’,19,‘男’,‘湖北宜昌’,5);
insert into student values(‘2010009’,‘Hunk’,19,‘男’,‘湖北武汉’,4);
insert into student values(‘2010010’,‘Jim’,18,‘男’,‘湖北襄樊’,3);
create table computer
(
studentid varchar(20) references student(studentid),
score float
)
insert into computer values(‘2010001’,90);
insert into computer values(‘2010002’,80);
insert into computer values(‘2010003’,70);
insert into computer values(‘2010004’,60);
insert into computer values(‘2010005’,75);
insert into computer values(‘2010006’,85);

–1查询出学生的编号,姓名,计算机成绩

select s.studentid 学生编号,s.studentname 姓名,c.score 计算机成绩
from student s
left join computer c
on s.studentid=c.studentid

–2查询参加过考试的学生信息

select student.*
from student,computer
where student.studentid = computer.studentid

–3查询出学生的编号、姓名、所在班级名称、计算机成绩

select student.studentid 编号,studentname 姓名,classname 班级名称,score 计算机成绩
from student
left join computer
on student.studentid = computer.studentid
right join class
on student.classid = class.classid

–4查询出年龄大于19岁的学生编号、姓名、计算机成绩

select student.studentid 编号,studentname 姓名,studentage 年龄,score 计算机成绩
from student
left join computer
on student.studentid = computer.studentid
where studentage > 19

–5查询出姓名中包含有c的学生编号、姓名、计算机成绩

select student.studentid 编号,studentname 姓名,score 计算机成绩
from student
left join computer
on student.studentid = computer.studentid
where studentname like "%c%"

–6查询出计算机成绩大于80分的学生编号、姓名、班级名称

select student.studentid 编号,studentname 姓名,score 成绩,classname 班级名称
from student,class,computer
where computer.score > 80 and student.classid = class.classid and student.studentid = computer.studentid

–7查询出所有学生的信息和计算机成绩信息

select student.*,score
from student
left join computer
on student.studentid = computer.studentid

–8查询出每个班的学生的计算机成绩的平均分,最高分,最低分

select classname 班级名称,avg(score) 平均分, max(score) 最高分,min(score) 最低分
from class,computer,student
where student.studentid = computer.studentid and student.classid = class.classid
group by classname

–9查询显示出班级的计算机平均分大于80的班级名称、平均分信息,并按照平均分降序显示

select classname 班级名称,avg(score) 平均分
from class,computer,student
where student.studentid = computer.studentid and student.classid = class.classid
group by classname
having 平均分 > 80
order by 平均分 desc

–10查询出和Jim住在同一个地方的学生的基本信息

select *
from student
where studentaddress = (select studentaddressfrom studentwhere studentname = "Jim"
)

–11查询出班级编号大于3的学生基本信息

select *
from student
where student.classid > 3

–12查询出班级编号大于3的学生的计算机平均分信息

select avg(score) 平均分
from class,computer,student
where class.classid > 3 and student.classid = class.classid and student.studentid = computer.studentid

–13查询出班级编号大于3的男生的学生信息

select student.*
from student
left join computer
on student.studentid = computer.studentid
right join class
on student.classid = class.classid
where class.classid > 3

–14查询男、女生的计算机平均成绩、最高分、最低分

select studentsex 性别,avg(score) 平均分,max(score) 最大值,min(score) 最小值
from student
left join computer
on student.studentid = computer.studentid
group by 性别
select studentsex 性别,avg(score) 平均分,max(score) 最大值,min(score) 最小值
from student,computer
where student.studentid = computer.studentid
group by 性别

–15将参加过考试的学生的年龄更改为20

update student,computer
set studentage = 20
where student.studentid = computer.studentid

–16查询出每个班级的学生的平均分(查询的结果中包含平均分和班级名称)

select classname 班级名称,avg(score) 平均分
from class,computer,student
where student.studentid = computer.studentid and student.classid = class.classid
group by 班级名称

–17删除姓名包含“c”字符的学生计算机成绩

update student,computer
set score = null
where studentname like "%c%" and student.studentid = computer.studentid

–18查询出G1T07班学生的编号、姓名、班级名称、计算机成绩

select student.studentid 编号,studentname 姓名,classname 班级名称,score 计算机成绩
from student,computer,class
where classname = "G1T07" and student.studentid = computer.studentid and student.classid = class.classid

–19查询出年龄在20-25之间的学生的编号、姓名、年龄、计算机成绩

select student.studentid 编号,studentname 姓名,studentage 年龄,score 计算机成绩
from student,computer,class
where studentage >=20 and studentage <=25 and student.studentid = computer.studentid and student.classid = class.classid
select student.studentid 编号,studentname 姓名,studentage 年龄,score 计算机成绩
from student,computer,class
where studentage between 20 and 25 and student.studentid = computer.studentid and student.classid = class.classid

–20查询出成绩最高的学生的编号、姓名、计算机成绩、所在班级名称

select student.studentid 编号,studentname 姓名,score 计算机成绩,classname 班级名称
from student,computer,class
where score = (select max(score)from computer
)
and student.studentid = computer.studentid and student.classid = class.classid

–21查询统计出每个班的平均分、显示平均分超过70分的信息、并按照降序显示信息

select classname 班级名称,avg(score) 平均分
from student,class,computer
where student.studentid = computer.studentid and student.classid = class.classid
group by 班级名称
having 平均分 > 70
order by 平均分 desc

mysql数据库 二十一练习题 及答案 (mysql练习题)相关推荐

  1. mysql数据库 二十一练习题 及答案 (mysql练习题)

    数据库二十一练习题 create table class ( classid int primary key, classname varchar(20) ) insert into class va ...

  2. mysql数据库笔试题库和答案mysql语句(后端面试必备)

    数据库笔试题库(入门基础篇) 一.入门基础题 `基础查询` `条件查询` `高级查询` `多表查询`

  3. Mysql数据库(十一)——MHA高可用集群部署及故障切换

    Mysql数据库(十一)--MHA高可用集群部署及故障切换 一.MHA概述 二.MHA的组成 三.MHA的特点 四.案例环境 1.服务器配置 2.思路 3.关闭防火墙和安全机制,并进行主从配置 4.配 ...

  4. mysql数据库慕课答案_智慧树MySQL数据库设计与应用慕课答案

    智慧树MySQL数据库设计与应用慕课答案 更多相关问题 [单选] TDD-LTE中一个子帧包含()时隙, [多选] 调整天线下倾角可以改变:() [单选] 多级破碎时,总破碎比等于多机破碎比的(). ...

  5. mysql练习题及答案_mysql练习题及答案.doc

    mysql练习题及答案 mysql练习题及答案 mysql查询语句练习题 Sutdent表的定义 字段名 字段描述 数据类型 主键 外键 非空 唯一 自增 Id 学号 INT 10 是 否 是 是 是 ...

  6. 2022年计算机二级考试MySQL数据库程序设计冲刺题及答案

    题库来源:优题宝公众号 2022年计算机二级考试MySQL数据库程序设计冲刺题及答案,由优题宝公众号根据最新计算机二级考试MySQL数据库程序设计大纲与历年计算机二级考试MySQL数据库程序设计真题汇 ...

  7. Mysql数据库(十一)unique index 唯一索引

    Mysql数据库(十一)unique index 唯一索引 唯一索引和普通索引: 1.都是能够加快搜索速度 2.唯一索引中的值不允许重复,普通索引的值允许重复 表contacts 建表语句如下,其中, ...

  8. 电脑上mysql数据库无法登录_无法远程登入MySQL数据库的几种解决办法MySQL综合 -电脑资料...

    方法一: 尝试用MySQL Adminstrator GUI Tool登入MySQL Server,Server却回复错误讯息:Host '60-248-32-13.HINET-IP.hinet.ne ...

  9. linux下使用的mysql数据库,Linux下安装以及使用MySQL数据库

    1.官网下载mysql数据库:https://dev.mysql.com/downloads/mysql/ 2.linux 下可直接下载:wget https://cdn.mysql.com//Dow ...

最新文章

  1. mybatis参数有list和实体类_Mybatis的几种传参方式,你了解吗?
  2. 微信小程序:开发之前要知道的三件事
  3. 写博客必备的复制黏贴
  4. r8169驱动下载linux,CentOS自带R8169驱动与R8168网卡之间的烦恼
  5. php 后门代码_分析一段PHP的后门代码,很恶心
  6. 计算机图形图像电影论文,计算机图形图像绘制技术地现状分析及应用发展.doc...
  7. 在linux上执行.net Console apps
  8. 小伙工资单被同事看到后遭开除!网友炸锅了 最新后续来了...
  9. PC服务器实现海量数据存取的方法
  10. Hinton反思新作:我说反向传播不好,但还是没谁能颠覆它
  11. 面向服务架构十大技术与基础理论
  12. C#:根据特定分隔符分割字符串
  13. Web前端-HTTP Cache-control
  14. smartadmin mysql_SmartAdmin 一套基于SpringBoot和Vue前后端分离的互联网企业级的通用型中后台解决方案...
  15. idea 2018汉化包(附使用教程)
  16. JS判断当前浏览器是否为IE内核
  17. 两万字深度讲解系统设计!超详细解析!面试复习必备!
  18. 破解服务中共性问题的繁琐处理方式——接入 API 网关
  19. Unity和Autodesk:通过更高效的工作流程提供沉浸式体验
  20. Pangu and Stones(区间DP)

热门文章

  1. mysql在指定列后面添加多列
  2. 笔记本触摸板失灵(失效)_开关
  3. Python Tutorial
  4. Youtube上面的Red5 官方视频下载教程,带字幕【亲测成功】
  5. HCIA -----ensp 基本配置 修改设备密码
  6. PCIe之DMA (三)
  7. Oracle Data Guard Feature 12cR2系列(一)
  8. STM8L051F3P6TR 定时器2两路PWM输出+死区控制+端口重映射PC5PC6
  9. 小学莲山课件网 计算机教案,小学信息技术《文字裱在书卷上》教案
  10. 天涯明月刀服务器维护了,《天涯明月刀》3月9日服务器例行维护公告