oracle查询语句执行顺序

完整的查询语句类似是这样的:

select ..., ROWNUM
  from table
 where <where clause>
 group by <columns> having <having clause> order by <columns>; 

它的处理顺序是:

  1. 首先,执行 FROM/WHERE 语句
  2. 为结果赋予 ROWNUM 并同时根据 FROM/WHERE 语句进行 rownum 过滤
  3. 执行 SELECT
  4. 执行 GROUP BY
  5. 执行 HAVING
  6. 执行 ORDER BY

PS: 如果存在分析函数(row_number etc),那么,分析函数的执行会在 order by 之前。

猜你喜欢

转载自blog.csdn.net/qq_39860189/article/details/77864133