1. <tfoot id='II4Z7'></tfoot>
  2. <legend id='II4Z7'><style id='II4Z7'><dir id='II4Z7'><q id='II4Z7'></q></dir></style></legend>

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

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

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

      什么是“ORDER BY (SELECT NULL)"?意思是?

      时间:2023-10-08
          <tbody id='qlTXI'></tbody>
      1. <small id='qlTXI'></small><noframes id='qlTXI'>

              <bdo id='qlTXI'></bdo><ul id='qlTXI'></ul>

              <tfoot id='qlTXI'></tfoot>
            • <i id='qlTXI'><tr id='qlTXI'><dt id='qlTXI'><q id='qlTXI'><span id='qlTXI'><b id='qlTXI'><form id='qlTXI'><ins id='qlTXI'></ins><ul id='qlTXI'></ul><sub id='qlTXI'></sub></form><legend id='qlTXI'></legend><bdo id='qlTXI'><pre id='qlTXI'><center id='qlTXI'></center></pre></bdo></b><th id='qlTXI'></th></span></q></dt></tr></i><div id='qlTXI'><tfoot id='qlTXI'></tfoot><dl id='qlTXI'><fieldset id='qlTXI'></fieldset></dl></div>
              <legend id='qlTXI'><style id='qlTXI'><dir id='qlTXI'><q id='qlTXI'></q></dir></style></legend>
              1. 本文介绍了什么是“ORDER BY (SELECT NULL)"?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                以下 SQL 来自 Itzik Ben-Gan,用于生成数字表.order by (select null) 部分是什么意思?谢谢.

                The following SQL is from Itzik Ben-Gan that is used to generate a numbers table. What does the order by (select null) part mean? Thanks.

                DECLARE @number_of_numbers INT;
                SELECT @number_of_numbers = 100000;
                
                WITH    a AS ( SELECT   1 AS i
                               UNION ALL
                               SELECT   1
                             ),
                        b AS ( SELECT   1 AS i
                               FROM     a AS x ,
                                        a AS y
                             ),
                        c AS ( SELECT   1 AS i
                               FROM     b AS x ,
                                        b AS y
                             ),
                        d AS ( SELECT   1 AS i
                               FROM     c AS x ,
                                        c AS y
                             ),
                        e AS ( SELECT   1 AS i
                               FROM     d AS x ,
                                        d AS y
                             ),
                        f AS ( SELECT   1 AS i
                               FROM     e AS x ,
                                        e AS y
                             ),
                        numbers
                          AS ( SELECT TOP ( @number_of_numbers )
                                        ROW_NUMBER() OVER ( ORDER BY ( SELECT   NULL
                                                                     ) ) AS number
                               FROM     f
                             )
                    SELECT  *
                    FROM    numbers;
                

                谢谢!

                推荐答案

                ROW_NUMBER 在语法上需要 ORDER BY 子句.没有它你就不能使用它.SELECT NULL 是一种在不强制执行任何特定命令的情况下关闭错误的技巧.在这种情况下,我们不需要强制执行任何顺序,因此最快的选择是使用 SELECT NULL.

                ROW_NUMBER requires an ORDER BY clause syntactically. You cannot use it without one. SELECT NULL is a hack to shut up the error while not enforcing any particular order. In this case we don't need to enforce any order, so the fastest option is to use SELECT NULL.

                优化器看穿了这个技巧,所以它没有运行时成本(通过查看执行计划很容易验证这个说法).

                The optimizer sees through this trick, so it has no runtime cost (this claim is easily verified by looking at the execution plan).

                这篇关于什么是“ORDER BY (SELECT NULL)"?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何从 SQL Server 中的值列表中进行选择 下一篇:如何在 SELECT FROM 语句中使用表类型?

                相关文章

              2. <legend id='qgIus'><style id='qgIus'><dir id='qgIus'><q id='qgIus'></q></dir></style></legend>
                • <bdo id='qgIus'></bdo><ul id='qgIus'></ul>

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