dent
where name LIKE '李%'
order by math+chinese+english desc;
32.统计一个班级共有多少学生?
select count(*) as 总人数
from student;
33.统计数学成绩大于80的学生有多少个?
select count(*) as 总人数
from student
where math > 80;
34.统计总分大于250的人数有多少?
select count(*) as 总人数
from student
where (math+chinese+english) > 250;
select count(english) as 总人数
from student;//13
select count(math) as 总人数
from student;
35.统计一个班级数学总成绩。
select sum(math)
from student;
select sum(name)
from student;//0
36.统计一个班级语文、英语、数学各科的总成绩。
select sum(math) as 数学总分,sum(chinese) as 语文总分,sum(english) as 英语总分
from student;
37.统计一个班级语文、英语、数学的成绩总和。
select sum(math)+sum(chinese)+sum(english) as 班级总分
from student;
38.统计一个班级语文成绩平均分。
select sum(math)/count(math)
from student;
select sum(math)/count(*)
from student;
总结:
(1).delete from 或truncate table或drop table的各自的区别:
delete from:按行删除表中的所有记录,但会保留表,适合删除数据量不大的数据,可按条件删除
truncate table:复制原表结构-〉一次性删除整表 -> 自动恢复原表结构,适合删除数据量较大的数据,不能按条件删除
drop table:删除表本身
删除记录时,一定要留意表间的关联关系
(2).排序:NULL值为最小,使用order by子句,默认升序,order by子句必须放置在最后
(3).复合函数
(1)count()函数,统计之用,不统计NULL值
(2)sum()函数,统计和之用,不要统计非数值,如果统计非数值,返回0
(4).合计函数
avg()
max(),min(),当max()和min()函数位于日期类型时,分别取得最近日期和最早日期