<tfoot id='GRjMo'></tfoot>

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

    2. <small id='GRjMo'></small><noframes id='GRjMo'>

    3. <legend id='GRjMo'><style id='GRjMo'><dir id='GRjMo'><q id='GRjMo'></q></dir></style></legend>
        • <bdo id='GRjMo'></bdo><ul id='GRjMo'></ul>
      1. 从 SQL Server 表中随机选择 n 行

        时间:2023-07-18

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

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

                <legend id='fGTn3'><style id='fGTn3'><dir id='fGTn3'><q id='fGTn3'></q></dir></style></legend>
                • <bdo id='fGTn3'></bdo><ul id='fGTn3'></ul>
                  本文介绍了从 SQL Server 表中随机选择 n 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含大约 50,000 行的 SQL Server 表.我想随机选择大约 5,000 行.我想到了一个复杂的方法,创建一个带有随机数"列的临时表,将我的表复制到其中,循环遍历临时表并使用 RAND() 更新每一行,然后从该表中选择随机数列<0.1.我正在寻找一种更简单的方法来做到这一点,如果可能的话,在一个语句中.

                  I've got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I've thought of a complicated way, creating a temp table with a "random number" column, copying my table into that, looping through the temp table and updating each row with RAND(), and then selecting from that table where the random number column < 0.1. I'm looking for a simpler way to do it, in a single statement if possible.

                  本文建议使用NEWID() 函数.这看起来很有希望,但我不知道如何可靠地选择一定百分比的行.

                  This article suggest using the NEWID() function. That looks promising, but I can't see how I could reliably select a certain percentage of rows.

                  以前有人这样做过吗?有什么想法吗?

                  Anybody ever do this before? Any ideas?

                  推荐答案

                  select top 10 percent * from [yourtable] order by newid()
                  

                  针对关于大表的纯垃圾"评论:您可以这样做以提高性能.

                  In response to the "pure trash" comment concerning large tables: you could do it like this to improve performance.

                  select  * from [yourtable] where [yourPk] in 
                  (select top 10 percent [yourPk] from [yourtable] order by newid())
                  

                  这样做的成本将是值的键扫描加上连接成本,这在选择百分比很小的大表上应该是合理的.

                  The cost of this will be the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

                  这篇关于从 SQL Server 表中随机选择 n 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用于选择两个日期之间的日期的 SQL 查询 下一篇:没有了

                  相关文章

                    <tfoot id='X54lQ'></tfoot>
                  1. <small id='X54lQ'></small><noframes id='X54lQ'>

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

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