SQL中随机选取数据的方法
mysql:
select * from tablename order by rand() limit 10
sqlserver:
select top 10 * from tablename order by NEWID()
NEWID
创建 uniqueidentifier 类型的唯一值。
语法
NEWID ( )
返回类型
uniqueidentifier
例子:把随机选取的数据存入其它数据库
insert Tests (UserID,Name) select top 3 UserID,Name from Users order by NewID()
select * from Tests
select * from Tests