MySQL (basic) Aggregate functions

Source: Internet
Author: User
1. Aggregate Function 1.1.COUNT () function 1. the COUNT () function is used to COUNT the number of records. 2. it is used with the GOUPEBY keyword. I still use the t_student table here. You can create a table by yourself and it is not necessary to be exactly the same as me. example: query the total number of students in the t_student table MysqlSELECTCOUNT (*) AStotalFR

1. Aggregate Function 1.1. COUNT () function 1. the COUNT () function is used to COUNT the number of records. 2. it is used together with the goupe by keyword. I still use the t_student table here. you can create your own table exercises without having to be exactly the same as me. example: query the total number of students in the t_student table MysqlSELECT COUNT (*) AS 'Total' FR

Zookeeper

I. Aggregate functions

1.1. COUNT () function

1. The COUNT () function is used to COUNT the number of records;

2. Used with the goupe by keyword;

I am still using the t_student table. You can create a table on your own and do not need to be exactly the same as me.

For example, query the total number of students in the t_student table.

Mysql> select count (*) AS 'Total' FROM t_student;

Example: query the number of students in each grade in the t_student table.

Mysql> select count (*) AS 'Total', gradeName FROM t_student group by gradeName;

1.2. SUM () function

1. The SUM () function is the SUM function;

2. Used with the goupe by keyword;

Example: query the total age of all students in the t_student table.

Mysql> select sum (age) AS 'Age SUM 'FROM t_student;

For example, query the total age of all students in the t_student table and group them by grade.

Mysql> select sum (age) AS 'Age sume', gradeName FROM t_student group by gradeName;

1.3. AVG () function

1. The AVG () function is a function used to calculate the average value;

2. Used with the goupe by keyword;

For example, query the average age of all students in the t_student table.

Mysql> select avg (age) AS 'average age' FROM t_student;

For example, query the average age of all students in the t_student table and group them by grade.

Mysql> select avg (age) AS 'average age', gradeName FROM t_student group by gradeName;

1.4. MAX () function

1. the MAX () function is the function for finding the maximum value;

2. Used with the goupe by keyword;

For example, the largest age among all students in the t_student table is queried.

Mysql> select max (age) AS 'maximum age' FROM t_student;

Example: query the t_student table for students of the largest age in each grade.

Mysql> select max (age) AS 'maximum age', gradeName FROM t_student group by gradeName;

1.5. MIN () function

1. The MIN () function is the function for minimum value;

2. Used with the goupe by keyword;

Example: query the t_student table for all the youngest students

Mysql> select min (age) AS 'minimum age' FROM t_student;

Example: query the t_student table for the youngest student in each grade.

Mysql> select min (age) AS 'minimum age', gradeName FROM t_student group by gradeName;


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.