MySQL aggregate function

Source: Internet
Author: User

MySQL aggregate functions are commonly used with five SUM COUNT AVG Min/max

AVG ([DISTINCT] expr)
Returns the average of expr. The DISTINCT option can be used to return the average of different values of expr.
SELECT Gender, AVG (age) from student
GROUP by gender;

COUNT (expr)
Returns the number of non-null values in the row retrieved by the SELECT statement.
SELECT COUNT (*) from student; --Returns the number of rows retrieved, regardless of whether they contain null values

SELECT COUNT (name) from student; --Returns the non-null value of the row retrieved by the SELECT statement
The number

MIN ([DISTINCT] expr), MAX ([DISTINCT] expr)
Returns the minimum and maximum values for expr
SELECT MIN (age), MAX (age) from student;

SUM ([DISTINCT] expr)
Returns the total number of expr
SELECT SUM (age) from student;


This article is from "Yun Weibang" blog, please be sure to keep this source http://aklaus.blog.51cto.com/9724632/1597527

MySQL aggregate function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.