MySQL数据库 每日练习

-- 1. 完成以下练习题
-- 新建一个 成绩表 
-- 	1) ID 主键,
-- 	2) 学号  唯一键
-- 	3) 姓名  非空
-- 	4)   科目  非空
-- 	5)成绩   保留一位小数
create table t_score(
	id int primary key comment '主键',
	stu_num varchar(20) unique comment '学号',
	stu_name varchar(10) not null comment '姓名',
	stu_sub varchar(50) not null comment '科目',
	stu_score double(11,1)  comment '成绩'
);
-- 录入相关的测试数据
insert into t_score(id,stu_num,stu_name,stu_sub,stu_score) value
(1,'2020101','张三','高数','85'),
(2,'2020102','李一','英语','63'),
(3,'2020103','李二','英语','78'),
(4,'2020104','李三','英语','76.5'),
(5,'2020105','李四','英语','83'),
(6,'2020106','王一','物理','26'),
(7,'2020107','王二','物理','59.5'),
(8,'2020108','王三','物理','85'),
(9,'2020109','王四','物理','22'),
(10,'2020110','小明','高数','13'),
(11,'2020111','小红','高数','69'),
(12,'2020112','小绿','高数','70');
-- 1.  查询 姓名中 包含 二 的所有学生对应的成绩
select stu_score from t_score where stu_name like '%二%';
-- 2.  查询 学生中每一门科目对应的最高成绩、最低成绩
select stu_sub ,min(stu_score),max(stu_score) from t_score group by stu_sub;
-- 3.  查询 学生中 英语最高成绩对应的信息
select * from t_score where stu_score = (select max(stu_score) from t_score where stu_sub = '英语') and stu_sub = '英语';
-- 4. 查询 学生 语文最高成绩 和最低成绩差了多少分

select max(stu_score) - min(stu_score) from t_score where stu_sub = '英语'  
-- 5. 查询 语文超过平均分的信息
select * from t_score where stu_sub = '英语' and stu_score > (select avg(stu_score) from t_score)

-- 6. 查询 语文成绩在80分的人数
select * from t_score where stu_sub = '英语' and stu_score = '83'
-- 7. 查询语文课程的成绩、并按照从大到小的顺序排列
select stu_score from t_score where stu_sub = '英语' order by stu_score desc
-- 8. 查询 科目超过平均分5人的 科目及平均分
 select subject from s_socer t where exists(
 select a.* from
 (select f.subject, avg(f.socer) as socerd from s_socer f group by f.subject) a where t.subject = '语文' and t.socer > a.socerd+5);
-- 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值