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. spa