一个学生表
分别记录姓名,年龄,性别,班级,语文,数学,英语字段
create table student2(
id int primary key ,
name char(20),
sex char(10),
age int(3),
mobile char(20),
class char(10),
english int(10),
chinese int(10),
math int(10)
)engine=innodb default charset=utf8;
insert into student2 values
(1,'小红','女',23,'13813828824','1719',77,88,98),
(2,'小明','男',23,'13713713711','1720',56,66,55),
(3,'小李','男',23,'15915913911','1719',78,64,87),
(4,'小张','男',23,'15915913912','1720',77,76,77),
(5,'小白','女',24,'15915913913','1719',90,89,98),
(6,'小陈','女',19,'15915913914','1719',84,100,81),
(7,'小钱','女',20,'15915913915',null,45,99,93);
题目
题目1
查询1719班学生的成绩信息
SELECT name,english,chinese,math from student2 where class=1719 ;
题目2
查询1719班学生语文成绩大于80小于90的学生信息
SELECT id,name,chinese from student2 where class=1719 and chinese>80 and chinese<90;
题目3
查询学生表中5-7行的数据信息
select * from student2 limit 4,3;
题目4
显示1719班英语成绩为90,数学成绩为98的name与mobile信息
SELECT name,mobile from student2 where class=1719 and english=90 and math=98;
题目5
显示1719班学生信息并且以语文成绩降序排序
SELECT * from student2 where class=1719 order by chinese desc
题目6
查询1719与1720班,语文成绩与数学成绩都小于80的name与mobile信息
SELECT name,mobile from student2 where class in (1719,1720) and chinese<80 and math<80;
select name,mobile from student2 where chinese<80 and math<80 and (class=1719 or class=1720);
select name,mobile from student2 where ( chinese<80 and math<80 and class=1719 )or (chinese<80 and math<80 and class=1720);
题目7
查询英语平均分大于80分的班级,英语平均分
显示:班级和平均分
条件:avg english>80
SELECT class,avg(english) as e from student2 group by class having e>80;
SELECT avg(english),class from student2 group by class having avg(english)>80;
题目8
按班级查出数学最高分
SELECT class,max(math) from student2 group by class ;
题目9
查询出每班数学最低分
SELECT class,min(math) from student2 group by class ;
题目10
查询每班数学总分
SELECT class,sum(math) from student2 group by class ;
题目11
查询每班数学平均分
SELECT class,avg(math) from student2 group by class ;
题目12
查询出每班学生总数
SELECT class,count(id) from student2 group by class ;
SELECT class,count(*) from student2 group by class ;
题目13
在表中插入一条小谢的成绩数据
insert into student2 values(8,'小谢','男',20,'15915913918',null,55,97,90);
题目14
把英语分数小于60的同学分数改为60分
update student2 set english=60 where english<60;