这个SQL语句的执行顺序是什么 [英] What is the order of execution for this SQL statement

查看:35
本文介绍了这个SQL语句的执行顺序是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 SQL 查询,

I have below SQL Query,

SELECT TOP 5 C.CustomerID,C.CustomerName,C.CustomerSalary
FROM Customer C
WHERE C.CustomerSalary > 10000
ORDER BY C.CustomerSalary DESC

正确解释下面的执行顺序是什么,

What will be execution order of the following with proper explanation ,

  1. 顶部条款
  2. WHERE 子句
  3. 按条款排序

推荐答案

查看 SELECT 文档声明,特别是本节:

SELECT 语句的逻辑处理顺序

Logical Processing Order of the SELECT statement

以下步骤显示逻辑处理顺序,或绑定order,用于 SELECT 语句.此顺序确定对象何时在一个步骤中定义的内容可用于后续的子句脚步.例如,如果查询处理器可以绑定(访问)在 FROM 子句中定义的表或视图、这些对象及其列可用于所有后续步骤.反过来,因为 SELECT 子句是第 8 步,所以任何列别名或派生该子句中定义的列不能被前面的引用条款.但是,它们可以被后续子句引用,例如ORDER BY 子句.注意实际的物理执行语句由查询处理器决定,顺序可能会有所不同从此列表中.

The following steps show the logical processing order, or binding order, for a SELECT statement. This order determines when the objects defined in one step are made available to the clauses in subsequent steps. For example, if the query processor can bind to (access) the tables or views defined in the FROM clause, these objects and their columns are made available to all subsequent steps. Conversely, because the SELECT clause is step 8, any column aliases or derived columns defined in that clause cannot be referenced by preceding clauses. However, they can be referenced by subsequent clauses such as the ORDER BY clause. Note that the actual physical execution of the statement is determined by the query processor and the order may vary from this list.

给出以下顺序:

FROM
ON
JOIN
WHERE
GROUP BY
WITH CUBE or WITH ROLLUP
HAVING
SELECT
DISTINCT
ORDER BY
TOP

这篇关于这个SQL语句的执行顺序是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆