MySQL database basic usage-aggregation-grouping

Source: Internet
Author: User

Polymerization
    • 5 aggregation functions are available for fast statistical data
    • COUNT (*) means that the total number of rows is computed, the parentheses are written with the name of the column, and the result is the same
    • Query the total number of students
Select COUNT (*) from students;

  

    • Max (column) indicates the maximum value for this column
    • Max number of girls queried
Select Max (ID) from students where gender=0;

  

    • Min (column) indicates the minimum value for this column
    • Query the minimum number of students who have not been deleted
Select  from where isdelete=0;

    • The sum (column) indicates which of this column is calculated and
    • After you've queried the boys ' numbers,
Select SUM (ID) from students where gender=1;

  

    • AVG (column) indicates the average of this column
    • Query does not remove the female number average
Select SUM (ID) from students where gender=1;

  

Group
    • Group By field, indicating that the same data in this field is placed in a group
    • After grouping, only the same data columns can be queried, and data columns that have differences cannot appear in the result set
    • You can count the grouped data and do the aggregation operations.
    • Grammar
Select column 1, column 2, aggregation ... from table name Group BY column 1, column 2, column 3 ....
    • Number of men and women queried
Select Gender as Gender, COUNT (*) from studentsgroup by gender;

Check the number of cities

MySQL database basic usage-aggregation-grouping

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.