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)