方式1. 随机采样,抽取百分之5 的数据 rand(id)<0.05
-- 随机采样
-- create table tmp_info_ycf as
-- select * from info_ycf where rand(policy_id )< 0.03 limit 20000 ;
-- ;
方式2. 根据某个字段进行统计,数据尽量均匀,
create table tmp_info_ycf as
-- insert overwrite table tmp_info_ycf
select *
from (
select *, cluster_sample(70) over(partition by city_code) as flag
from info_ycf ) sub
where flag = true;
方式3.降采样,在数据类别分布不均衡的时候,采用 case when col='c1' then rand(id )< rat1 when col='c2' then rand(id )< rat2 end
如果类别过多的话,直接统计各个类别对应的比例,然后采用join 的形式进行,对类别多的数据进行rand()范围限制