例如;
NO         NUMBER
1          13900000000
2          13900000001
……
10000      13900009999
作以下操作
select * from test order by NEWID()再分页!
按下一页会有重复的NUMBER???

解决方案 »

  1.   

    order by newid() 每次排序都是随机的
      

  2.   

    那道理,就算是随机排序,也不应该有重复的。所以肯定是你的上一页下一页,没有从本地的记录集中fetch出来,而是每次都select了一次,所以你看page 1的时候做了一次select,排序了一次,然后再看page2的时候,又call了一次select,于是又随即排序了一次
      

  3.   

    你debug下看看,或者profiler一下看看,是不是select * from ... order by newid()每次看分页都作了一次
      

  4.   

    如果code没问题的话,selecct * from... order by newid()应该只做了一次
      

  5.   

    order by newid() 是随机排序,所以是不会重复的
    但如果你翻页是通过服务端实现的,那就会有问题了,所以这样的翻页要用客户端实现
      

  6.   

    我是在ASP中作的,贴出看看!
    就是你说的:
    page 1的时候做了一次select,排序了一次,然后再看page2的时候,又call了一次select,于是又随即排序了一次!
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"> 
    <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> 
    <td width="9" rowspan="2"></td>
              <td class="12v"> 
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="12v">
                  <tr> 
                    <td class="12v" > 
                      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" id="AutoNumber3" height="0" width="100%">
                        <tr> 
                          <td>
                            <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6699ff">
                              <tr> 
                                <td height="20"> 
                                  <div align="center" class="style1">
                                    <p>东 莞 搜 房 资 讯 手 机 号 码 信 息 一 览 表</p>
                                    <p>13642370000-13642399999</p>
                                  </div>
                                </td>
                              </tr>
                              <tr> 
                                <td height="140" valign="top" bgcolor="#E8F1FF"><br>
                                  <%'开始分页
    Const MaxPerPage=900
        dim totalPut   
        dim CurrentPage
        dim TotalPages
        dim j
        dim sql
         if Not isempty(request("page")) then
           currentPage=Cint(request("page"))
        else
           currentPage=1
        end if 
     set rs=server.createobject("adodb.recordset")
    rs.open "select * from test order by NEWID()",conn,1,1
      
    if err.number<>0 then
    response.write "数据库中无数据"
    end if

       if rs.eof And rs.bof then
            Response.Write "<p align='center' class='contents'> 温馨提示:没有号码可供删除!</p>"
        else
       totalPut=rs.recordcount       if currentpage<1 then
               currentpage=1
           end if       if (currentpage-1)*MaxPerPage>totalput then
        if (totalPut mod MaxPerPage)=0 then
          currentpage= totalPut \ MaxPerPage
        else
           currentpage= totalPut \ MaxPerPage + 1
        end if
           end if        if currentPage=1 then
                 showContent
                 showpage totalput,MaxPerPage,"number_test.asp"
            else
               if (currentPage-1)*MaxPerPage<totalPut then
                 rs.move  (currentPage-1)*MaxPerPage
                 dim book
                 book=rs.book
                 showContent
                  showpage totalput,MaxPerPage,"number_test.asp"
             else
             currentPage=1
                showContent
                showpage totalput,MaxPerPage,"number_test.asp"
           end if
        end if
            end if    sub showContent
            dim i
        i=0 %>
                                  <table width="88%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
                                    <form name="form1" method="post" action="houjie_100.asp?action=del">
                                      <tr>
                                        <td width="27%" bgcolor="#E8F1FF"><div align="center">号码列表</div>
                                          <div align="center"></div>                                      <div align="center"></div></td> 
                                      </tr>
                                      <%do while not rs.eof%>
                                      <tr>
                                        <td bgcolor="#E8F1FF" style="PADDING-LEFT: 6px"><div align="center"><%=rs("number")%></div>                                      <div align="center"></div>                                      </td> 
                                      </tr>
                                      <%i=i+1
    if i>=MaxPerPage then Exit Do
    rs.movenext
      loop
      rs.close
      set rs=nothing%>
                                    </form>
                                  </table>
                                  <%  
    End Sub   
      
    Function showpage(totalnumber,maxperpage,filename)  
       Dim n
      
    If totalnumber Mod maxperpage=0 Then  
    n= totalnumber \ maxperpage  
    Else
    n= totalnumber \ maxperpage+1  
    End If

    Response.Write "<form method=Post action="&filename&">"  
    Response.Write "<p align='center' class='contents'> "  
    If CurrentPage<2 Then  
    Response.Write "<font class='contents'>首页 上一页</font> "  
    Else  
    Response.Write "<a href="&filename&"?page=1 class='contents'>首页</a> "  
    Response.Write "<a href="&filename&"?page="&CurrentPage-1&" class='contents'>上一页</a> "  
    End If

    If n-currentpage<1 Then  
    Response.Write "<font class='contents'>下一页 尾页</font>"  
    Else  
    Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&" class='contents'>"  
    Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"  
    End If  
    Response.Write ""  
    Response.Write "<font class='contents'> 共有<font color=red>"&totalnumber&"</font>条手机号" 
    Response.Write "<font class='contents'>转到:</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="&currentpage&">"  
    Response.Write "&nbsp;<input type='submit'  class='contents' value='GO' name='cndok' ></form>"  
    End Function  
    %>
                                </td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
              </td>
              <td class="12v" width="9" rowspan="2"></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <br>
      

  7.   

    number_test.asp这个每翻页一次就运行一次?
      

  8.   

    显然出问题了rs.open "select * from test order by NEWID()",conn,1,1你这样的话,上一页,下一页,每次都要访问一次页面。服务器每次都会做一次select,等于rs做了两次不同的随机排序
      

  9.   

    我不知道asp中的Session是否可以保存object, 如果可以的话,应该设一个session标志,在适当的时候保存select出来的rs,然后翻页时读取保存起来的rs,这样对了,否则么次都select一边,翻页的时候读取不同的排序
      

  10.   

    或者还有一个办法,不是很推荐,因为访问量大的话会造成负担把select ... orderby newid()的东西 into 到一张 #table里面,这样在从#table里面拿东西,用完后删除。不过很难估算什么时候应该删除临时表