在SQL Server中ORDER BY NEWID()
有什么好处?
答案 0 :(得分:2)
尽管没有提出任何真正的问题,但可以使用NEWID()以“随机”方式对数据集进行排序,但是在大量记录上效率不高:
/*Smaller Datasets*/
Select top 100 *
from dbo.SomeTable
Order by NEWID() DESC
/*For very large datasets, this seems to be more effiecient*/
Select top 100 *
from dbo.SomeTable
where
(ABS(CAST((BINARY_CHECKSUM(*) * RAND()) as int)) % 100) < 10