MySQL语法顺序:
SELECT DISTINCT
<select_list>
FROM
<left_table> <join_type>
JOIN <right_table> ON <join_condition>
WHERE
<where_condition>
GROUP BY
<group_by_list>
HAVING
<having_condition>
ORDER BY
<order_by_condition>
LIMIT <limit_number>
解析顺序:
-- 行过滤
FROM <left_table>
## 第二步和第三步会循环执行
ON <join_condition>
<join_type> JOIN <right_table>
## 第四步会循环执行,多个条件的执行顺序是从左往右的
WHERE <where_condition>
GROUP BY <group_by_list>
HAVING <having_condition>
-- 列过滤
## 分组之后才会执行SELECT
SELECT
DISTINCT <select_list>
-- 排序
ORDER BY <order_by_condition>
-- MySQL附加
LIMIT <limit_number>