<i id='1d6iB'><tr id='1d6iB'><dt id='1d6iB'><q id='1d6iB'><span id='1d6iB'><b id='1d6iB'><form id='1d6iB'><ins id='1d6iB'></ins><ul id='1d6iB'></ul><sub id='1d6iB'></sub></form><legend id='1d6iB'></legend><bdo id='1d6iB'><pre id='1d6iB'><center id='1d6iB'></center></pre></bdo></b><th id='1d6iB'></th></span></q></dt></tr></i><div id='1d6iB'><tfoot id='1d6iB'></tfoot><dl id='1d6iB'><fieldset id='1d6iB'></fieldset></dl></div>
      1. <tfoot id='1d6iB'></tfoot>

          <bdo id='1d6iB'></bdo><ul id='1d6iB'></ul>

        <small id='1d6iB'></small><noframes id='1d6iB'>

      2. <legend id='1d6iB'><style id='1d6iB'><dir id='1d6iB'><q id='1d6iB'></q></dir></style></legend>
      3. MySQL查询/子句执行顺序

        时间:2023-08-17
            <tbody id='nb9C9'></tbody>
          • <tfoot id='nb9C9'></tfoot>
            <legend id='nb9C9'><style id='nb9C9'><dir id='nb9C9'><q id='nb9C9'></q></dir></style></legend>

              <i id='nb9C9'><tr id='nb9C9'><dt id='nb9C9'><q id='nb9C9'><span id='nb9C9'><b id='nb9C9'><form id='nb9C9'><ins id='nb9C9'></ins><ul id='nb9C9'></ul><sub id='nb9C9'></sub></form><legend id='nb9C9'></legend><bdo id='nb9C9'><pre id='nb9C9'><center id='nb9C9'></center></pre></bdo></b><th id='nb9C9'></th></span></q></dt></tr></i><div id='nb9C9'><tfoot id='nb9C9'></tfoot><dl id='nb9C9'><fieldset id='nb9C9'></fieldset></dl></div>
                <bdo id='nb9C9'></bdo><ul id='nb9C9'></ul>

                <small id='nb9C9'></small><noframes id='nb9C9'>

                  本文介绍了MySQL查询/子句执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 MySQL 中执行子句的预定义顺序是什么?其中一些是在运行时决定的,这个顺序是否正确?

                  • FROM 子句
                  • WHERE 子句
                  • GROUP BY 子句
                  • HAVING 子句
                  • SELECT 子句
                  • ORDER BY 子句

                  解决方案

                  MySQL 语句的实际执行有点棘手.但是,该标准确实指定了查询中元素的解释顺序.这基本上是按照您指定的顺序,尽管我认为 HAVINGGROUP BY 可以在 SELECT 之后:

                  • FROM 子句
                  • WHERE 子句
                  • SELECT 子句
                  • GROUP BY 子句
                  • HAVING 子句
                  • ORDER BY 子句

                  这对于理解查询的解析方式很重要.例如,您不能在 WHERE 子句中使用 SELECT 中定义的列别名,因为 WHERESELECT 之前被解析.另一方面,这样的别名可以在 ORDER BY 子句中.

                  至于实际执行,这真的取决于优化器.例如:

                  <预><代码>...按 a、b、c 分组按空排序

                  <预><代码>...按 a、b、c 分组按 a, b, c 排序

                  两者都有 ORDER BY 根本没有被执行的效果——所以在 GROUP BY 之后不会被执行(在第一种情况下,效果是从 GROUP BY 中删除排序,第二个效果是只做 GROUP BY 已经做的事情).

                  What is the predefined order in which the clauses are executed in MySQL? Is some of it decided at run time, and is this order correct?

                  • FROM clause
                  • WHERE clause
                  • GROUP BY clause
                  • HAVING clause
                  • SELECT clause
                  • ORDER BY clause

                  解决方案

                  The actual execution of MySQL statements is a bit tricky. However, the standard does specify the order of interpretation of elements in the query. This is basically in the order that you specify, although I think HAVING and GROUP BY could come after SELECT:

                  • FROM clause
                  • WHERE clause
                  • SELECT clause
                  • GROUP BY clause
                  • HAVING clause
                  • ORDER BY clause

                  This is important for understanding how queries are parsed. You cannot use a column alias defined in a SELECT in the WHERE clause, for instance, because the WHERE is parsed before the SELECT. On the other hand, such an alias can be in the ORDER BY clause.

                  As for actual execution, that is really left up to the optimizer. For instance:

                  . . .
                  GROUP BY a, b, c
                  ORDER BY NULL
                  

                  and

                  . . .
                  GROUP BY a, b, c
                  ORDER BY a, b, c
                  

                  both have the effect of the ORDER BY not being executed at all -- and so not executed after the GROUP BY (in the first case, the effect is to remove sorting from the GROUP BY and in the second the effect is to do nothing more than the GROUP BY already does).

                  这篇关于MySQL查询/子句执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何修复:“找不到适合 jdbc:mysql://localhost/dbname 下一篇:在 MySQL 触发器中引发阻止表更新的错误

                  相关文章

                  最新文章

                  1. <legend id='O4qhu'><style id='O4qhu'><dir id='O4qhu'><q id='O4qhu'></q></dir></style></legend>

                      • <bdo id='O4qhu'></bdo><ul id='O4qhu'></ul>

                      <i id='O4qhu'><tr id='O4qhu'><dt id='O4qhu'><q id='O4qhu'><span id='O4qhu'><b id='O4qhu'><form id='O4qhu'><ins id='O4qhu'></ins><ul id='O4qhu'></ul><sub id='O4qhu'></sub></form><legend id='O4qhu'></legend><bdo id='O4qhu'><pre id='O4qhu'><center id='O4qhu'></center></pre></bdo></b><th id='O4qhu'></th></span></q></dt></tr></i><div id='O4qhu'><tfoot id='O4qhu'></tfoot><dl id='O4qhu'><fieldset id='O4qhu'></fieldset></dl></div>
                      <tfoot id='O4qhu'></tfoot>

                    1. <small id='O4qhu'></small><noframes id='O4qhu'>