select * from table where id = (convert(int,rand(100)*10))

解决方案 »

  1.   

    Q. How can I randomly sort query results?A. To randomly order rows, or to return x number of randomly chosen rows, you can use the RAND function inside the SELECT statement. But the RAND function is resolved only once for the entire query, so every row will get same value. You can use an ORDER BY clause to sort the rows by the result from the NEWID function, as the following code shows:SELECT *
    FROM Northwind..Orders 
    ORDER BY NEWID() SELECT TOP 10 * 
    FROM Northwind..Orders 
    ORDER BY NEWID() 
    —SQL Server MVPs
      

  2.   

    我用的是Access数据库,提示说NEWID函数未顶义
      

  3.   

    楼上不是废话吗?呵呵。我就嫌这样太繁才回问这个问题的。
    不过看来没办法了,我在SQL里面试upto给的语句是完全可行的,但到Access里就不行。
    没办法,老板要用Access。谢谢大家了。
    另外问一下,如果用Fill(ds)把记录全部都取出来,然后再挑选的话会不会很慢啊