找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
八、数据库单表练习题作业:

#创建学生表
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);

1,查询1832班的成绩信息
select chinese,english,math
from GRADE  
where class=1832;

2,查询1833班,语文成绩大于80小于90的所有成绩信息
select *
from GRADE
where class=1833 and chinese
between 80 and 90

3,查询学生表中5到10行的数据
select *
from GRADE
where id limit 4,11;

4,显示1832班英语成绩为98,数学成绩为77的姓名与学号,
select *
from GRADE
where class=1832 and english=98 or math=77;

5,查询出1832班成绩并且按语文成绩排序(降序)
select *
from GRADE
where class=1832 order by chinese desc;

6,查询1833班与1832班,语文成绩与数学成绩都小于80的姓名。
select *
from GRADE
where (class=1833 and chinese<80 and math<80)and (class=1832 and chinese<80 and math<80);
7,查询出没有参加语文考试的学生姓名和班级名称。
select *
from GRADE
where chinese is null;

8,求出班上语文成绩不及格的学生姓名
select *
from GRADE
where chinese<60;

9,求出每个班的数学平均成绩
select avg(math)
from GRADE;

10、求出每个班级语文成绩总分 --涉及到每个的时候都需要分组
select sum(chinese)
from GRADE
group by class;

11、将语文成绩不及格的学生语文成绩改为60分
update GRADE
set chinese=60
where chinese <60;

12、三科分数都大于70分的人名和年纪
select name age
from GRADE
where chinese>70 and english>70 and math>70;

13、求出英语分数高于70且其它任何一科目大于60分的人和班级
select name class
from GRADE
where english>70 and (math>60 or chinese>60);

14、统计每个班的人数
select count(*),class
from GRADE group
by class;

15、求每个班数学成绩大于80的人数
select count(math>80)
from GRADE GROUP
by class;

16、求出每个班英语成绩最高的分数和班级名称 --每个班英语成绩最高
select max(english)
from GRADE GROUP
by class;

17、给GRADE表增加3个字段(数据类型及长度自定义,建议要合理,
alter table GRADE add(history int(3),geography int(3),politics int(3));

分享至 : QQ空间
收藏
您需要登录后才可以回帖 登录 | 立即注册