数据库二十一练习题
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);

select * from class;
select * from computer;
select * from student;

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

select class.classid as 编号,studentname as 姓名,score as 计算机成绩
from student,class,computer
where student.classid = class.classid and student.studentid = computer.studentid
1
2
3
–2查询参加过考试的学生信息

select student.*
from student,computer
where student.studentid = computer.studentid
1
2
3
–3查询出学生的编号、姓名、所在班级名称、计算机成绩

select student.studentid 编号,studentname 姓名,classname 班级名称,score 计算机成绩
from student,class,computer
where student.studentid = computer.studentid and student.classid = class.classid
1
2
3
–4查询出年龄大于19岁的学生编号、姓名、计算机成绩

select student.studentid 编号,studentname 姓名,studentage 年龄,score 计算机成绩
from student,computer
where studentage > 19 and student.studentid = computer.studentid
1
2
3
–5查询出姓名中包含有c的学生编号、姓名、计算机成绩

select student.studentid 编号,studentname 姓名,score 计算机成绩
from student,computer
where student.studentname like “%c%” and student.studentid = computer.studentid
1
2
3
–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
1
2
3
–7查询出所有学生的信息和计算机成绩信息

select *
from student,computer
where student.studentid = computer.studentid
1
2
3
–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
1
2
3
4
–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
1
2
3
4
5
6
–10查询出和Jim住在同一个地方的学生的基本信息

select *
from student
where studentaddress = (
select studentaddress
from student
where studentname = “Jim”
)
1
2
3
4
5
6
7
–11查询出班级编号大于3的学生基本信息

select *
from student
where student.classid > 3
1
2
3
–12查询出班级编号大于3的学生的计算机平均分信息

select avg(score) 平均分
from class,computer,student
where class.classid > 3 and student.classid = class.classid and student.studentid = computer.studentid
1
2
3
–13查询出班级编号大于3的男生的学生信息

select student.*
from class,computer,student
where class.classid > 3 and studentsex = “男” and student.classid = class.classid and student.studentid = computer.studentid
1
2
3
–14查询男、女生的计算机平均成绩、最高分、最低分

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

update student,computer
set studentage = 20
where student.studentid = computer.studentid
1
2
3
–16查询出每个班级的学生的平均分(查询的结果中包含平均分和班级名称)

select classname 班级名称,avg(score) 平均分
from class,computer,student
where student.studentid = computer.studentid and student.classid = class.classid
group by 班级名称
1
2
3
4
–17删除姓名包含“c”字符的学生计算机成绩

update student,computer
set score =null
where studentname like “%c%” and student.studentid = computer.studentid
1
2
3
–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
1
2
3
–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
1
2
3
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
1
2
3
–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
1
2
3
4
5
6
7
–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. QIIME 2教程. 10数据导出Exporting data(2020.11)
  2. 计算机视觉实习岗面试准备(一.基础知识)
  3. 即日起更新机器学习相关博客
  4. react-native 安卓支持 gif动态图
  5. tree的使用,显示行号,find命令应用
  6. Java POI 导出EXCEL经典实现 Java导出Excel
  7. 泊位调度问题 matlab,流水线车间调度问题matlab源程序.doc
  8. php和html的怎么结合,php和html怎么结合,我要做seesion验证啊。。。
  9. 介绍一个开源的SIP(VOIP)协议库PJSIP
  10. Xamarin.Android和UWP之MVVM的简单使用(二)
  11. BugkuCTF-Reverse题入门逆向多解法
  12. 中国邻苯二甲酸二环己酯(DCHP)行业市场供需与战略研究报告
  13. 如何找到一个好的Joomla主机提供商
  14. Win10装Ubuntu双系统步骤做法
  15. 《剑指offer》面试题21——包含min函数的栈(C++)
  16. [导入]网络安全工作者的必杀技
  17. JavaScript(JS)网页--动态生成表格
  18. 不需要写代码,快速批量修改文件夹中图片的格式
  19. 在Excel中输入身份证号码的方法或批量改为文本格式
  20. Linux HaProxy安装/启动/简单配置教程

热门文章

  1. 剑指offer06:从尾到头打印链表
  2. SQL Server IS NULL语句使用举例
  3. python open encoding_Python文件操作
  4. 网络口协商_以太网端口协商原理
  5. linux caffe生成的模型,深度学习之pytorch转caffe转ncnn模型转换(三)
  6. php mencache扩展,【memcache缓存专题(3)】PHP-memcache扩展的安装以及使用
  7. python程序设计与应用第4章实验
  8. mysql 列合并_实战讲解MySQL执行计划,面试官当场“要了我”
  9. java可以连接php吗_java - 需要PHP或Java代码才能使用多个Internet连接
  10. java 构建树形结构_Java求助:如何建立一个树形结构