美文网首页
Sql执行顺序

Sql执行顺序

作者: BoilingSpring | 来源:发表于2016-09-22 09:16 被阅读0次

SQL is implemented as if a query was executed in the following order:

FROM clause

WHERE clause

GROUP BY clause

HAVING clause

SELECT clause

ORDER BY clause

For most relational database systems, this order explains which names (columns or aliases) are valid because they must have been introduced in a previous step.

So in Oracle and SQL Server, you cannot use a term in the GROUP BY clause that you define in the SELECT clause because the GROUP BY is executed before the SELECT clause.

There are exceptions though: MySQL and Postgres seem to have additional smartness that allows it.

相关文章

网友评论

      本文标题:Sql执行顺序

      本文链接:https://www.haomeiwen.com/subject/azczettx.html