当前位置: 数据库>mysql
MySQL笔记之函数查询的使用
来源: 互联网 发布时间:2014-10-08
本文导语: 参考表 count()用来统计记录的条数 代码如下:mysql> select count(*) from score;mysql> select count(*) from score where stu_id=901; sum()求和函数 代码如下:mysql> select sum(grade) from score;mysql> select id,sum(grade) from score where stu_id=901; avg()求平均值函数 ...
参考表
mysql> select count(*) from score;
mysql> select count(*) from score where stu_id=901;
mysql> select sum(grade) from score;
mysql> select id,sum(grade) from score where stu_id=901;
mysql> select avg(grade) from score where c_name='计算机';
mysql> select c_name,avg(grade) from score group by c_name;
max()求最大值函数
mysql> select c_name,max(grade) from score where c_name='英语';
mysql> select c_name,max(grade) from score group by c_name;
min()求最小值函数
mysql> select c_name,min(grade) from score where c_name='中文';
mysql> select c_name,min(grade) from score group by c_name;
Concat拼接函数
mysql> select Concat(c_name, '(', stu_id, ')')
-> from score order by stu_id;
count()用来统计记录的条数
代码如下:
mysql> select count(*) from score;
mysql> select count(*) from score where stu_id=901;
sum()求和函数
代码如下:
mysql> select sum(grade) from score;
mysql> select id,sum(grade) from score where stu_id=901;
avg()求平均值函数
代码如下:
mysql> select avg(grade) from score where c_name='计算机';
mysql> select c_name,avg(grade) from score group by c_name;
max()求最大值函数
代码如下:
mysql> select c_name,max(grade) from score where c_name='英语';
mysql> select c_name,max(grade) from score group by c_name;
min()求最小值函数
代码如下:
mysql> select c_name,min(grade) from score where c_name='中文';
mysql> select c_name,min(grade) from score group by c_name;
Concat拼接函数
代码如下:
mysql> select Concat(c_name, '(', stu_id, ')')
-> from score order by stu_id;