当前位置:网站首页>Total / statistics function of MySQL

Total / statistics function of MySQL

2022-07-06 17:25:00 Cute new vegetable dog

total / Statistical function

count function

select count(*) from student;
select count(*) from student where math > 90;
  • count(*) and count( Column ) The difference between
    • count(*) Return the number of rows of records that meet the conditions
    • count( Column ) Count the number of columns that meet the conditions , But it will be excluded as null

sum function

  • sum Functions only work with numbers , Otherwise, an error will be reported
  • For multi column summation , It can't be less .
--  Count the total score of mathematics in a class 
select sum(math) from student;
--  Count the total score of each subject in a class 
select sum(english),sum(math),sum(chinese) from student;
--  Count the total scores of three subjects in a class 
select sum(english+math+chinese) from student;
--  The average score of a Chinese class is one 
select sum(chinese) / count(*) from student;

avg function

--  Average score of Statistical Mathematics 
select avg(math) from student;
--  Average score of statistical total score 
select avg(math + english + chinese) from student;

max/min function

--  Ask for the highest and lowest score of the class 
select max(math + english + chinese) , min(math + chinese + english) from student;
--  Seek the highest and lowest scores in class mathematics 
select max(math),min(math) from student;
原网站

版权声明
本文为[Cute new vegetable dog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060928149131.html