sql 采样

11 篇文章 1 订阅

方式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()范围限制 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mtj66

看心情

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值