找回密码
 立即注册
gz_29chm +好友
这个人很懒什么都没写
听众
1
主题
0
金钱
18
个人名片
  • 未填写地址
  • 这家伙很懒什么都没写
粉丝关注
还没有人关注TA
添加表情

0509 mysql 课堂作业

已有 150 次阅读2021-5-9 17:00 | 作业

-------------------------------------------表数据填充----------------------------------------------------
CREATE TABLE `student`  (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `class` int(20) NULL DEFAULT NULL,
  `name` varchar(20) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,
  `math` int(4) NULL DEFAULT NULL,
  `chinese` int(4) NULL DEFAULT NULL,
  `english` int(4) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ;

INSERT INTO `student` VALUES (1, 1831, 'chen', 44, 55, 66);
INSERT INTO `student` VALUES (2, 1831, '11', 44, 98, 66);
INSERT INTO `student` VALUES (3, 1831, 'fs1', 90, 55, 66);
INSERT INTO `student` VALUES (4, 1831, 'vvv', 44, 55, 77);
INSERT INTO `student` VALUES (5, 1832, '55', 87, 67, 66);
INSERT INTO `student` VALUES (6, 1832, 'hhh', 67, 89, 66);
INSERT INTO `student` VALUES (7, 1833, 'www', 78, 44, 98);
INSERT INTO `student` VALUES (8, 1833, 'ttt', 77, 89, 88);
INSERT INTO `student` VALUES (9, 1833, 'ii', 78, 97, 60);
INSERT INTO `student` VALUES (10, 1833, 'eee', 86, 61, 69);
INSERT INTO `student` VALUES (11, 1832, 'shddaks', NULL, NULL, NULL);
INSERT INTO `student` VALUES (12, 1833, 'dferr', NULL, NULL, NULL);


-----------------------------------------------------答案-------------------------------------------------
1、查询1832班的成绩信息
select * from student where class='1832';
2,查询1833班,语文成绩大于80小于90的成绩信息
select * from student where class='1833' and chinese BETWEEN 80 and 90;
3,查询学生表中5到10行的数据
SELECT * from student LIMIT 5,10;
4,显示1832班英语成绩为98,数学成绩为77的姓名与学号,
SELECT * from student where class='1832' and english =98 and math=77;
5,查询出1832班成绩并且按语文成绩排序(降序)
select * from student where class ='1832' order by chinese desc;

6,查询1833班与1832班,语文成绩与数学成绩都小于80的姓名。
SELECT * from student where (class ='1832' or class ='1833') and chinese <80 and english <80;
7,查询出没有参加语文考试的学生姓名和班级名称。
SELECT class,name from student where chinese is null;
8,求出班上语文成绩不及格的学生姓名
select * from student where chinese <60 or chinese is null;
9,求出每个班的数学平均成绩
select class,avg(math) from student GROUP BY class ;
10、求出每个班级语文成绩总分 --涉及到每个的时候都需要分组
select class,sum(chinese) from student GROUP BY class ;

11、将语文成绩不及格的学生成绩改为60分
update student set chinese = 60 where chinese <60;
12、三科分数都大于70分的人名和年纪
SELECT name from student where chinese >70 and english >70 and math >70;
13、求出英语分数高于70且其它任何一科目大于60分的人和班级
SELECT name,class from student where english >70 and (chinese >60 or math >60);
14、统计每个班的人数
SELECT class,count(*) from student GROUP BY class;
15、求每个班数学成绩大于80的人数
SELECT count(1) from student where math >80;
16、求出每个班英语成绩最高的那个人的姓名和班级名称 --每个班英语成绩
最高
SELECT class,max(english) from student GROUP BY class;
17、给student表增加3个字段(数据类型及长度自定义,建议要合理),
alter table student add (age int(4),hobbit varchar(20),high int(4));
18、创建一个”dcs”远程用户授予该用户只有查询的权限

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册