SQL server 中SELSECT查询语句的执行顺序如下:
(8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list>
(12)INTO<new_table>
(1) FROM <left_table> (3) <join_type> JOIN <right_table> (2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE | ROLLUP}
(7) HAVING <having_condition>
(10) ORDER BY <order_by_list> [ASC|DESC]
注意:where条件不能使用聚合函数 having可以使用