MySQL Common basic operational Syntax (vii)--statistical function and group query "command line mode"

Source: Internet
Author: User

Note: The text of all ... Represents more than one.
1. Use the Count Statistics bar number: Select count (field name ...) ) from TableName;

2. Use AVG to calculate the average of the field: Select AVG (field name) from TableName;

This can be properly expanded, such as adding conditions, renaming, and so on.
3. Sum with sum: select sum (field name) from TableName;

4. Use Max and Min to find maximum and minimum values:

5. Note: When using these functions, if there is no data in the database, Count returns 0, the other returns null;

6. Use GROUP by to Group data: Select Field name ... From tablename GROUP By field name ... , grouping, sorting, statistics and so on can be combined to use, in practical applications are also more like this:

7. Use the Group_concat () implementation to display fields in no group:


8. If you want to add a condition to a grouped query, you must use having, not where:

9. If you want to sort by using conditional grouping, the order by must be at the back of the having:

MySQL Common basic operational Syntax (vii)--statistical function and group query "command line mode"

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.