MySQL Database notes-basic queries (grouping, aggregation functions)

Source: Internet
Author: User

SELECT COUNT (*) from T_employee WHERE fage=23; View number
ALTER TABLE t_employee ADD fsubcompany VARCHAR (20);
ALTER TABLE t_employee ADD fdepartment VARCHAR (20); Add two columns to the T_employee table
UPDATE t_employee SET fsubcompany= ' Beijing ', fdepartment= ' development ' WHERE fnumber= ' DEV001 '; After you add two fields, you also need to update the two field values of the existing rows in the table.

An aggregate function is provided in SQL to perform statistics such as the number of statistics result sets, the maximum value of a field, the minimum value of a field, the average of a field, and the aggregate value of a field.
Data groupings are used to divide data into logical groups so that each group can be aggregated. The GROUP BY clause is used in SQL statements to group by, using the Group by Group field. The grouping statement must and aggregate function one
, the GROUP BY clause is responsible for dividing the data into logical groups, while the aggregation function counts each one.

SELECT Fage from T_employee GROUP by Fage;//View the age of the company's employees
SELECT Fage from t_employee;//View Company employees all ages
SELECT Fage,avg (fsalary) from T_employee GROUP by Fsubcompany,fdepartment;


SELECT Fage,count (*) as Countofthisage from T_employee GROUP by fage;//see the number of employees per age
SELECT Fsubcompany,avg (fsalary) as Fsalarysum from T_employee GROUP by Fsubcompany;
SELECT Fage,count (*) as Countofthisage from T_employee GROUP by Fage have COUNT (*) >1; Search for an age of 1 extra people

MySQL Database notes-basic queries (grouping, aggregation functions)

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.