抽样的问题····
现在需要写一个抽样的语句,需要在表中每隔 1000 条抽出一条数据,一共要抽出1000条。
请问下有大神们有什么意见和思路没,给点,先谢谢。
在线等。
[解决办法]
;with t as ( select row_number() over (order by id) as Row ,* from [Table])select * from t where r % 1000 = 0select * from t where r % 1000 = 1select * from t where r % 1000 = 2select * from t where r % 1000 = 3......select * from t where r % 1000 = 999
[解决办法]
;with ach as( select *,rid=row_number() over (order by getdate()) from tb),cte as( select *,nid=row_number() over (partition by (rid-1)/1000 order by rid) from ach)select *from ctewhere nid = convert(int,rand()*1000)
[解决办法]
select identity(int,1,1) id,* into #t from t
select * from #t where id%1000 = 1 order by id