Group (group by) the polymerization is generally used in combination with
(1) grouped by sex inquiry
select gender from students group by gender;
Number (2) query grouped by gender and statistics for each group
select gender, count (*) from students group by gender;
(3) query statistics grouped by gender and age of each group of the largest
select gender, max (age) from students group by gender;
The total number of (4) Query men
select count(*) from students where gender=1;
(5) The total number of queries men (not recommended, instead of the standard SQL statements)
the SELECT Gender, COUNT (*) Students from the WHERE Gender = 1;
(6) The masculine gender query field
select gender from students where gender = 1 ;
(7) the total number of queries men (recommended standard SQL statements, group by group sex, where sex is the label for each group)
the SELECT Gender, COUNT (*) Students from the WHERE Group by Gender Gender = 1;
(
GROUP_CONCAT () within each group member information for describing;
After having positioned group by, followed by defining conditions for each packet, each of these conditions will be set as a single element, the function of the polymerization conditions employed.
Distinction having and where, although both are related to later defined conditions, but is different elements defining
)
(8) after the query packet is greater than the average age of each group 15 and outputs the name of each member, age, and the average age of ID;
select gender,group_concat(name,' ',age,' ',ID),avg(age) from students group by gender having avg(age)>15;
(9)查询分组后每组平均年龄大于15的组别并输出每组成员的姓名,年龄,ID及其平均年龄;
select gender,group_concat(name,' ',age,' ',ID) from students group by gender having count(*)>2;