SELECT * FROM t1.student;
#查询学生的平均分
select name as '姓名',(chinese+english+math)/3 as '平均分' from student;
#查询名为赵云的成绩
select name,chinese,english,math from student where name='赵云';
#查询英语大于90分的同学
select name,english from student where english>90;
#查询总分大于200分的所有同学
select * from student where (chinese+english+math)>200;
#查询math>60并且id>90的学生成绩
select * from student where math>60 and id >90;
#查询总分大于200分并且数学成绩小于语文成绩的姓韩的同学。alter
select * from student where (chinese+english+math)>200 and math<chinese and name like '韩%';
#查询英语成绩大于语文成绩的同学
select * from student where english>chinese ;
#查询英语分数在80-90之间的同学alter
select * from student where english between 80 and 90;
select * from student where english>=80 and english<=90;
#查询分数学分数为89,90,91的同学。
select * from student where math=89 or math =90 or math = 91;
#查询所有性李的同学的成绩
select * from student where name like '李%';
#查询数学分数大于80,语文分数大于80的同学a
select * from student where math >80 and chinese >80;
#查询语文分数在70-80之间的同学
select * from student where chinese >=70 and chinese<=80;
select * from student where chinese between 70 and 80;
#查询总分为189,190,191的同学
select * from student where (chinese+english+math)>189 or (chinese+math+english)>190 or (chinese+math+english)>191;
#查询所有姓李或者性宋的学生成绩
insert into student values (8,'李广',99,99,99);
select * from student where name like '李%' or name like '宋%';
#查询数学比语文多30分的同学
select * from student where chinese >math+30;
#对数学成绩排序后升序输出
#order by 默认是升序
select * from student order by math;
#对姓名为李的学生的成绩升序输出
select * from student where name like '李%' order by chinese ,english,math ;
#对总分按从高到低的顺序输出
#别名尽量取为英文名字
select name,(chinese+english+math) as total from student order by total desc;
update student set name='李小二' where name='韩顺平';
SET SQL_SAFE_UPDATES = 0;
#
# 统计函数
#count(*) 返回满足条件的记录的多行
#count(列) 统计满足条件的某列有多少个,但是会排除为null的情况
#计算班级有多少学成
select COUNT(*) from student;
select count(*) from student;
#计算一个班数学成绩大于90 的人数
select count(*) from student where math>90;
#计算总分大于250分的人数
select count(*) from student where (chinese+english+math)>250;
select count(name) from student where math>60;
#sum()函数的使用 只对数值型字段有用 对非数值型无统计意义
#计算一个班级数学总成绩
select sum(math) from student;
#计算一个班级语文,英语,数学各科的总成绩
select sum(chinese),sum(english),sum(math) from student;
#计算一个班语文,英语,数学的成绩总和
select sum(chinese+english+math) from student;
#统计一个班级语文成绩平均分
select sum(chinese)/count(*) from student;
#avg()函数的使用
#求一个班级的数学平均分
select avg(math) as '数学平均分' from student;
#求一个班级总分平均分
select avg(math+chinese+english) from student;
#max() min()函数的使用
select max(math) from student;
select min(math) from student;
#求班级总分的最高分与总分的最低分
select max(chinese+english+math) as '总分最高分',min(chinese+english+math) as '总分最低分'from student
