近6个月每月都有还款行为用户分析

-- 近6个月每月都有还款行为用户中(都没用、第一月用过后没再用、每月都用)线下转账的用户
-- 近6月的数据存放该表
create table open.t_ttt_0401(
    uid bigint
) WITH (appendonly=true) DISTRIBUTED BY (uid);

-- 这是这一批每个月都有信贷还款的用户
insert into open.t_ttt_0401
select
    uid
from (
    select
        to_char(f_business_time, 'YYYY-MM') as m,
        f_trans_buyer_user_id as uid
    from wallet.t_wallet_info
    where f_business_time>='2020-04-01'
    and f_business_time<'2020-10-01'
    and F_trans_seller_user_id in (select f_sp_user_id from fn.t_scenario_sp_map where F_sp_scenario in (40000,40001,40002))
    and F_business_type in (5,6,7)
    and F_trans_type<>17
    and F_recvable_bank_user_id != 202
    group by m,uid
) t1 group by uid having count(*)=6;

-- 始终没有用线下转账的人
select
    uid
from (
    select
        uid,
        max(type) as type
    from (
        select
            uid,
            type
        from (
            select
                f_trans_buyer_user_id as uid,
                case when F_recvable_bank_user_id=8999 or F_recvable_bank_user_id=8998 then 'DaE'
                    else 'qiTa' end type
            from wallet.t_wallet_info t1
            left join open.t_ttt_0401 t2 on t1.f_trans_buyer_user_id=t2.uid
            where f_business_time>='2020-04-01'
            and f_business_time<'2020-10-01'
            and F_trans_seller_user_id in (select f_sp_user_id from fn.t_scenario_sp_map where F_sp_scenario in (40000,40001,40002))
            and F_business_type in (5,6,7)
            and F_trans_type<>17
            and F_recvable_bank_user_id != 202
            and t2.uid is not null
        ) t3 group by uid,type
    ) t4 group by uid having count(*)=1
) t5 where type='qiTa';

-- 近6个月中仅第一个月用过一次的用户
select
    f_trans_buyer_user_id
from wallet.t_wallet_info t5
left join (
    select
        uid
    from (
        select
            f_trans_buyer_user_id as uid
        from wallet.t_wallet_info t1
        left join open.t_ttt_0401 t2 on t1.f_trans_buyer_user_id=t2.uid
        where f_business_time>='2020-04-01'
        and f_business_time<'2020-10-01'
        and F_trans_seller_user_id in (select f_sp_user_id from fn.t_scenario_sp_map where F_sp_scenario in (40000,40001,40002))
        and F_business_type in (5,6,7)
        and F_trans_type<>17
        and (F_recvable_bank_user_id=8999 or F_recvable_bank_user_id=8998)
        and t2.uid is not null
    ) t3 group by uid having count(*)=1
) t4 on t5.f_trans_buyer_user_id=t4.uid
where f_business_time>='2020-04-01' and f_business_time<'2020-05-01'
and F_trans_seller_user_id in (select f_sp_user_id from fn.t_scenario_sp_map where F_sp_scenario in (40000,40001,40002))
and F_business_type in (5,6,7)
and F_trans_type<>17
and (F_recvable_bank_user_id=8999 or F_recvable_bank_user_id=8998)
and t4.uid is not null;

-- 每次都用了线下大额转账的人
select
    uid
from (
    select
        uid,
        max(type) as type
    from (
        select
            uid,
            type
        from (
            select
                f_trans_buyer_user_id as uid,
                case when F_recvable_bank_user_id=8999 or F_recvable_bank_user_id=8998 then 'DaE'
                    else 'qiTa' end type
            from wallet.t_wallet_info t1
            left join open.t_ttt_0401 t2 on t1.f_trans_buyer_user_id=t2.uid
            where f_business_time>='2020-04-01'
            and f_business_time<'2020-10-01'
            and F_trans_seller_user_id in (select f_sp_user_id from fn.t_scenario_sp_map where F_sp_scenario in (40000,40001,40002))
            and F_business_type in (5,6,7)
            and F_trans_type<>17
            and F_recvable_bank_user_id != 202
            and t2.uid is not null
        ) t3 group by uid,type
    ) t4 group by uid having count(*)=1
) t5 where type='DaE';

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值