1.分组 group by 字句的功能 select a,count(*) as num from product group by id; 注意 :是先分组再计算聚集函数;
2.having 过滤。过滤是基于分组-》聚集 之后的值进行过滤的。放在group by 之后。
3.where 和 having 的重要区别:where 在数据分组之前进行过滤 having 在数据分组聚集之后进行过滤。
4.order by 和 group by的区别:order by 可以对任意列使用。 group by 只能对select 后面紧跟的列用。
5.顺序 group by > having > order by.
6.select字句的顺序 select- from -where -group by-having -order by-limit.
使用子查询:
1.