dcsxlh

导航

 

 

个学生表

分别记录姓名,年龄,性别,班级,语文,数学,英语字段

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班学生的成绩信息

条件:class=1719  ,

 结果:english,chinese,math

SELECT    english,chinese,math  from  student2  where class="1719" ;

题目2

查询1719班学生语文成绩大于80小于90的学生信息

条件:class=179    chinese>80  and  chinese<90    * 是所有

结果:学生信息 *

方法:select * from student2  where class="1719" and chinese >80&&chinese<90   &&:并且

 

题目3

查询学生表中5-7行的数据信息

条件:  显示3 行(5,6,7)  Limit   4(索引) ,3(行数)

结果: 所有信息   * 

方法一:Limit   4(索引) ,3(行数)

 SELECT * from student2 limit 4,3;

方法二:SELECT * from student2 WHERE id BETWEEN 5 and 7; (缺陷)

 

题目4

显示1719班英语成绩为90,数学成绩为98的namemobile信息

结果:Name  mobile

条件: class="1719"   english=90     math=98  

 

题目5

显示1719班学生信息并且以语文成绩降序排序

结果:学生信息   *

条件:class=1719    chinese    desc

方法:SELECT * FROM student2 WHERE class IN(1719) ORDER BY chinese DESC ;

 

题目6

查询1719与1720班,语文成绩与数学成绩都小于80的namemobile信息

结果:name  mobile

条件: class="1719"  ,class=1720    ,chinese<80, math<80  

 方法一:

SELECT  NAME,mobile     from student2 WHERE (class=1719 or class=1720) and (chinese<80 and math<80);

方法二:

 select NAME,mobile from student2 WHERE chinese<80 AND math<80 and class in (1719,1720) ;

 方法三:

SELECT   name,mobile   from   student2 where (class=1719 and chinese<80 and math<80 )or (class=1720 and chinese<80 and math<80 ) 

方法四:SELECT name,mobile from student2 where (class=1719 or class=1720) and chinese<80 and math<80 ;

题目7

查询英语平均分大于80分的班级,英语平均分

 显示:班级和平均分       

条件:avg   english>80

 方法一:SELECT  class,avg(english) s from student2  GROUP BY  class  having s>80 ;

 

题目8

按班级查出数学最高分

 结果:max(math)

条件:班级(3个班)

方法一:select class,max(math)  from student2 GROUP BY class ;

 

题目9

查询出每班数学最低分

 条件 :min   group   by  分组

结果:每个班的最分

 

题目10

查询每班数学总分

 条件:sum

题目11

查询每班数学平均分

 条件:avg     group  by

 

题目12

查询出每班学生总数

 条件:count

题目13

在表中插入一条小谢的成绩数据

 

题目14

把英语分数小于60的同学分数改为60分

 

 

 

 

Limit   4(索引) ,3(行数)

posted on 2021-12-18 09:20  多测师_肖sir  阅读(78)  评论(0编辑  收藏  举报