[SQL]从表中随机选择部分行,并且对这些随机选取的行进行更新

使用的是MSSQLSever.

 

使用 

select top 50 percent * from [table] order by newid()

可以随机选取table的50%行。

 

使用

update randowmRecords
set 
    randowmRecords.[column] = [value]
from 
     (select top 50 percent * from [table] order by newid()) as  randowmRecords

可以随机更新50%行的对应列

 

 

 

Ref:

Select n random rows from SQL Server table

 

posted @ 2021-02-10 06:09  LLLZC  阅读(201)  评论(0编辑  收藏  举报