用oracle从每个分类中随机抽取10%的数据怎么实现

2025-03-04 22:58:10
推荐回答(2个)
回答1:

select col1,col2,type
from (select col1,col2,type,rn,max() over(partitio by type) as rn_max
from (select col1,col2,type,row_number() over (paritition by type order by dbms_random.value) as rn
from tablename ) t
) p
where rn/rn_max<=0.1
;

sample不确定能不能用分析函数,但是主要是用来全表取sample的

回答2:

select * from t1 sample(10) where 类型=‘’
union
select * from t1 sample(10) where 类型=‘’
...
几个类型分开取试试。