SELECT 语句的完整结构

  1. #sql92语法:
  2. SELECT ....,....,....(存在聚合函数)
  3. FROM ...,....,....
  4. WHERE 多表的连接条件 AND 不包含聚合函数的过滤条件
  5. GROUP BY ...,....
  6. HAVING 包含聚合函数的过滤条件
  7. ORDER BY ....,...(ASC / DESC )
  8. LIMIT ...,....
  9. #sql99语法:
  10. SELECT ....,....,....(存在聚合函数)
  11. FROM ... (LEFT / RIGHT)JOIN ....ON 多表的连接条件
  12. (LEFT / RIGHT)JOIN ... ON ....
  13. WHERE 不包含聚合函数的过滤条件
  14. GROUP BY ...,....
  15. HAVING 包含聚合函数的过滤条件
  16. ORDER BY ....,...(ASC / DESC )
  17. LIMIT ...,....

SQL语句的执行过程

FROM …,…-> ON -> (LEFT/RIGNT JOIN) -> WHERE -> GROUP BY -> HAVING -> SELECT -> DISTINCT ->ORDER BY -> LIMIT