mysql(二):使用聚合函数查询

count()函数
1.count()函数用来统计记录的条数
2.与group by关键字一起使用
例:select count(*) from t_grade;
        select count(*) as total from t_grade;
        select stuName,count(*)  from t_grade group by stuName;



sun() 函数
1. sun() 函数是求和函数
2. 与group by关键字一起使用
例:select stuName,sun(score) from t_grade where stuName="张三";
                          

         select stuName,sun(score) from t_grade group by stuName;
                         

avg() 函数
1. avg() 函数是求平均值函数
2. 与group by关键字一起使用
例: select stuName,avg(score) from t_grade where stuName="张三";
         select stuName,avg(score) from t_grade group by stuName;

max() 函数
1. max() 函数是求最大值函数
2. 与group by关键字一起使用
例: select stuName,course,max(score) from t_grade where stuName="张三";
         select stuName,max(score) from t_grade group by stuName;


min() 函数
1. min() 函数是求最小值函数
2. 与group by关键字一起使用
例: select stuName,course,min(score) from t_grade where stuName="张三";
         select stuName,min(score) from t_grade group by stuName;

猜你喜欢

转载自blog.csdn.net/qq_34802511/article/details/80939372