group by column_name (having 条件表达式)
group by通常和聚合函数(max(),min(),avg(),count()等)一起使用。如:count(*)求得所有行数,包括空值,count(列名)不包括空值。
having 条件表达式
对指定条件进行过滤,如:
select count(*) from readinfo where sex='女';统计所有女读者
select sex from readinfo group by sex;按性别分组,结果为:男,女
select sex,count(*) from readinfo group by sex;男读者有几人,女读者有几人
select sex from readinfo group by sex having count(sex)>2; 人数大于2的性别,按性别分组