SELECT *
FROM Northwind..Orders
ORDER BY NEWID()

A.
要赢得随机排序的列,只怕重回x条随机接纳的列,你能够采纳随机数。不过RAND函数在
二个询问中必须要回到贰个结出。你能够在NOWID函数重返的列上做OTiggoDER
BY。请看示例:

这段话翻译得真是难如登天,干脆不管原作,直接意译了。
不过提示我们留意,这种办法是要对总体表扫描,然后产生三个总括列再排序的,最棒不用
对大的表作那样的操作,不然会异常慢的。

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:

Q. How can I randomly sort query results?

SELECT *
FROM Northwind..Orders
ORDER BY NEWID()

—SQL Server MVPs

SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()

Q. 如何赢得随机排序结果?

SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()

本文适用于 SQL Server,Access 驱动未有 NEWID
函数,请参阅:怎么着从数据库中随机取n条记下。

相关文章