MySQL-SELECT语句执行顺序
SELECT语句执行顺序
- WITH (CTE, COMMON TABLE EXPRESSIONS)
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- HAVING
- SELECT, WINDOW FUNCTION
- SELECT DISTINCT
- UNION, INTERSECT, EXCEPT
- ORDER BY
- LIMIT, OFFSET
- FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR KEY SHARE
Window functions are permitted only in the select list and ORDER BY clause. Query result rows are determined from the FROM clause, after WHERE, GROUP BY, and HAVING processing, and windowing execution occurs before ORDER BY, LIMIT, and SELECT DISTINCT.
窗口函数仅在 select list 和 ORDER BY 子句中允许使用。查询结果行由 FROM 子句确定,在 WHERE、GROUP BY 和 HAVING 处理之后,窗口执行发生在 ORDER BY、LIMIT 和 SELECT DISTINCT 之前。
图示
https://twitter.com/abskoop/status/1709927917743112471

参考
窗口函数 VS SELECT DISTINCT
14.20.2 Window Function Concepts and Syntax
https://dev.mysql.com/doc/refman/8.0/en/window-functions-usage.html
MySQL SQL语句书写顺序和执行顺序
https://www.cnblogs.com/east7/p/14217030.html
distinct、 join on、where、group by、having、order by执行顺序
https://blog.csdn.net/xiaouncle/article/details/79960590
SELECT DISTINCT VS ORDER BY
http://www.postgres.cn/docs/12/sql-select.html
~~ ~~