标准sql执行顺序

  1:form 组装来自不同表的数据,如 form user或者,form user as u join goodsOrder as r on u.id= r.userid

  2:where 过滤符合查询条件的数据,如:id>1000

  3:group by 将查询数据进行分组

  4:使用sum等聚合函数进行计算。

  5:使用having 进行筛选分组。

  6:执行select语种

  7:执行排序语句

  如:select count(gid),gname from shopping_goods where gcid=1 group by gname having count(gid)>1 order by count(gid) desc

  1:首页查询shopping_goods 表,得到表中的数据

  2:执行where,过滤出gcid=1的商品。

  3:对gname进行分组。

  4:使用聚合函数count(),计算出商品类型为1,不同商品名称的数量.

  5:使用having,过滤出类型为1,商品统计数量大于1的商品

  6:执行select语句

  7:执行order by ,按照商品数量降序排列。

原文地址:https://www.cnblogs.com/wdx8927304/p/7783725.html