赞
踩
COUNT()
函数是用来统计记录的总条数。
select count(*/字段名) from 数据表;
根据提示,补充代码:tb_class
表,内容如下:
id | name | classid |
---|---|---|
1 | Emma | 366 |
2 | Mary | 367 |
3 | Allen | 367 |
4 | Kevin | 367 |
5 | Rose | 366 |
6 | James | 367 |
7 | Hale | 366 |
8 | David | 367 |
根据此表数据:
查询该表中一共有多少条数据;
查询此表中367 班
有多少位学生,以班级id
和对应人数格式输出。
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询该表中一共有多少条数据 ##########
- select count(*) from tb_class;
-
- ########## 查询此表中367班有多少位学生 ##########
- select classid,count(*) from tb_class where classid=367;
-
- ########## End ##########
SUM()
函数是对数据表的某列进行求和操作。
select sum(字段名) from 数据表;
根据提示,补充代码,一张tb_class
表,内容如下:
id | name | course | score |
---|---|---|---|
1 | Emma | 语文 | 86 |
2 | Mary | 语文 | 79 |
3 | Allen | 语文 | 92 |
4 | Emma | 英语 | 116 |
5 | Mary | 英语 | 95 |
5 | Allen | 英语 | 100 |
根据此表数据:
查询该表中学生的总成绩;
查询学生语文
课程的总分数。
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询所有学生总分数 ##########
- select sum(score) from tb_class;
-
- ########## 查询学生语文科目的总分数 ##########
-
- select course,sum(score) from tb_class where course='语文';
-
- ########## End ##########
AVG()
函数是对数据表的某列进行求平均值操作。
select avg(字段名) from 数据表;
根据提示,补充代码,一张tb_class
表,内容如下:
id | name | course | score |
---|---|---|---|
1 | Emma | 语文 | 86 |
2 | Mary | 语文 | 79 |
3 | Allen | 语文 | 92 |
4 | Emma | 英语 | 116 |
5 | Mary | 英语 | 95 |
5 | Allen | 英语 | 101 |
根据此表数据,查询表中该班级三位同学语文
和英语
课程的平均分数以及对应的课程名。
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询学生语文科目的平均分数 ##########
-
- select course,avg(score) from tb_class where course='语文';
-
- ########## 查询学生英语科目的平均分数 ##########
- select course,avg(score) from tb_class where course='英语';
-
-
- ########## End ##########
MAX()
函数是求某列的最大数值。
select max(字段名) from 数据表;
根据提示,补充代码,一张tb_class
表,内容如下:
id | name | course | score |
---|---|---|---|
1 | Emma | 语文 | 86 |
2 | Mary | 语文 | 79 |
3 | Allen | 语文 | 92 |
4 | Emma | 英语 | 116 |
5 | Mary | 英语 | 95 |
6 | Allen | 英语 | 100 |
根据此表数据,分别查询语文
和英语
课程中的最高分数。
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询语文课程中的最高分数 ##########
-
- select course, max(score) from tb_class where course='语文';
-
- ########## 查询英语课程中的最高分数 ##########
-
- select course, max(score) from tb_class where course='英语';
-
- ########## End ##########
MIN()
函数基本使用MIN()
函数是求某列的最小数值。
select min(字段名) from 数据表
根据提示,补充代码,tb_class
表,内容如下:
id | name | course | score |
---|---|---|---|
1 | Emma | 语文 | 86 |
2 | Mary | 语文 | 79 |
3 | Allen | 语文 | 92 |
4 | Emma | 英语 | 116 |
5 | Mary | 英语 | 95 |
5 | Allen | 英语 | 100 |
根据此表数据,分别查询语文
和英语
课程中的最低分数。
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询语文课程中的最低分数 ##########
-
- select course, min(score) from tb_class where course='语文';
-
- ########## 查询英语课程中的最低分数 ##########
-
- select course, min(score) from tb_class where course='英语';
-
- ########## End ##########
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。