八、数据库单表练习题作业:
#创建学生表
CREATE TABLE GRADE(
ID INT PRIMARY KEY AUTO_INCREMENT COMMENT'学号',
NAME VARCHAR(20) COMMENT'姓名',
AGE INT COMMENT'年龄',
CLASS INT COMMENT'班级',
CHINESE INT COMMENT'语文分数',
ENGLISH INT COMMENT'英语分数',
MATH INT COMMENT'数学分数'
)ENGINE=INNODB DEFAULT CHARSET=UTF8 COMMENT'学生表';
#插入表数据
insert into GRADE values
(1,'zhangsan',18,1832,80,90,77),
(2,'lisi',18,1832,90,90,90),
(3,'wangwu',19,1833,99,98,100),
(4,'zhaoliu',17,1833,85,78,85),
(5,'xiaoqi',17,1832,60,80,88),
(6,'xiaoba',18,1833,70,82,90);
select * from GRADE;
1,查询1832班的成绩信息
select class,CHINESE,ENGLISH,MATH from GRADE where class = 1832;
2,查询1833班,语文成绩大于80小于90的所有成绩信息
select class,chinese,english,math from GRADE where class = 1833 and CHINESE > 80 and CHINESE <90;
3,查询学生表中5到10
select *from GRADE where id limit 4,6;
4,显示1832班英语成绩为98,数学成绩为77的姓名与学号,
select id,name,class,english,math from GRADE where class ='1832' and english = 98 and math =77;
5,查询出1832班成绩并且按语文成绩排序(降序)
select * from GRADE where class ='1832' order by chinese desc;
6,查询1833班与1832班,语文成绩与数学成绩都小于80的姓名。
select name,class,chinese,math from GRADE where chinese > 80 and math > 80;
7,查询出没有参加语文考试的学生姓名和班级名称。
Select name,class,chinese from GRADE where chinese is null;
8,求出班上语文成绩不及格的学生姓名
Select name,class,chinese from GRADE where chinese < 60;
9,求出每个班的数学平均成绩
Select avg(math) from GRADE;
10、求出每个班级语文成绩总分 --涉及到每个的时候都需要分组
select sum(chinese),class from GRADE group by class;
11、将语文成绩不及格的学生语文成绩改为60分
update GRADE set chinese=60 where chinese<60;
12、三科分数都大于70分的人名和年纪
select age,name,chinese,english,math from GRADE where chinese >70 and english > 70 and math >70;
13、求出英语分数高于70且其它任何一科目大于60分的人和班级
select name,class,chinese,english,math from GRADE where english > 70 and chinese >60 or math >60;
14、统计每个班的人数
select count(class) from GRADE;
15、求每个班数学成绩大于80的人数
select count(class),math from GRADE where math > 80;
16、求出每个班英语成绩最高的分数和班级名称 --每个班英语成绩最高
select max(english),class from GRADE group by class;
17、给GRADE表增加3个字段(数据类型及长度自定义,建议要合理,
alter table GRADE add (PHONE bigint(11) not null,TIME date,HIEGHT int(3));
|
|