Mysql database notes-Basic queries (grouping and Aggregate functions)

Source: Internet
Author: User

Mysql database notes-Basic queries (grouping and Aggregate functions)

Select count (*) FROM T_Employee WHERE FAge = 23; // view the number of students alter table T_Employee ADD FSubCompany VARCHAR (20); alter table T_Employee ADD FDepartment VARCHAR (20 ); // Add two columns for the T_Employee table: UPDATE T_Employee SET FSubCompany = 'beijing', FDepartment = 'development' WHERE FNumber = 'dev001 '; // after adding the two fields, you must update the values of these two fields in the original data row of the table.

SQL provides an aggregate function to perform data statistics such as the number of statistical result sets, the maximum value of a field, the minimum value of a field, the average value of a field, and the total value of a field.
Data groups are used to divide data into multiple logical groups, so that each group can be aggregated. In SQL statements, the GROUP BY clause is used as the GROUP BY field ". The grouping statement must be used with aggregate function 1.
For use, the group by clause is responsible for dividing data into logical groups, while the aggregate function performs statistics on each GROUP.

SELECT FAge FROM T_Employee group by FAge; // SELECT FAge FROM T_Employee for the company's employees; // SELECT FAge, AVG (FSalary) for the company's employees of all ages) FROM T_Employee group by FSubCompany, FDepartment; SELECT FAge, COUNT (*) AS CountOfThisAge FROM T_Employee group by FAge; // view the number of employees in each age group select FSubCompany, avg (FSalary) AS FSalarySUM FROM T_Employee group by FSubCompany; SELECT FAge, COUNT (*) AS CountOfThisAge FROM T_Employee group by FAge having count (*)> 1; // only retrieve the age GROUP with 1 excess

 

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.