写的顺序:select ... from... where.... group by... having... order by.. limit [offset,]
(rows)
执行顺序:from... where...group by... having.... select ... order by... limit
group by 存在时,select中除了聚集函数外,所有的基本列必须是group by里面存在的;having基本上同group by一起使用的,having类似于where语句,只是having过滤是基于group by 分组后的数据,having一般通过select语句里面的聚集函数进行过滤。