找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
Mysql聚合函数
1.select count(*) from +表名;
统计查询数据的数量
例子:select count(*),class from student1 group by class;
注释:根据班级分组,然后求出每个班的人数。

2.select sum(字段) from +表名
查询某个字段求和

3.select avg(字段) from +表名
查询某个字段的平均值

4.select max(字段) from +表名
查询字段的最大值

5.select min(字段) from +表名
查询字段的最小值

6.select distinct(字段) from +表名
对某个字段进行去重


1.查询1832班的成绩信息
select chinese,english,math,class from student1 where class=1832;
2.查询1833班,语文成绩大于80小于90的成绩信息
select chinese,class from student1 where class=1833 and chinese>80 and chinese<90;
3.查询学生表中5到10行的数据
select * from student1 where id limit 4,5;
4.显示1832班英语成绩为98,数学成绩为77的姓名与学号
select name,id from student1 where english=98 and math=77;
5.查询出1832班成绩并且按语文成绩排序(降序)
select chinese  from student1 where class=1832 order by chinese desc;
6.查询1833班与1832班,语文成绩与数学成绩都小于80的姓名。
select name from student1 where chinese<80 and math<80 and class in(1832,1833);
7.查询出没有参加语文考试的学生姓名和班级名称。
select name,class from student1 where chinese is null;
8.求出班上语文成绩不及格的学生姓名 !!
select name from student1 group by chinese having chinese<60 or chinese is null;
9.求出每个班的数学平均成绩
select avg(math),class from student1 group by class;
10.求出每个班级语文成绩总分 --涉及到每个的时候都需要分组
select sum(chinese),class from student1 group by class;
11.将语文成绩不及格的学生成绩改为60分
update student1 set chinese=60 where chinese<60;
12.三科分数都大于70分的人名和年纪
select name,age from student1  where chinese>70 and math>70 and english>70;
13.求出英语分数高于70且其它任何一科目大于60分的人和班级
select name,class from student1  where english>70 and (math>60 or chinese>60);
14.统计每个班的人数
select count(id),class from student1 group by class;
15.求每个班数学成绩大于80的人数
select count(id),class from student1 where math>80 group by class;
16.求出每个班英语成绩最高的那个人的姓名和班级名称 --每个班英语成绩最高

17.给student表增加3个字段(数据类型及长度自定义,建议要合理)
alter table student1 add(history int(10) not null,tel int(10) not null,cumputer int(10) not null);

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册