招行理财金额频次分段SQL记录

# 招行理财、金额分段、频次分段
select
    amount_num as "金额分段",
    cishu as "频次分段",
    sum(total_amount) as "总交易额",
    sum(total_chengben) as "总成本",
    sum(meiren_bishu) as "总笔数",
    count(F_trans_buyer_user_id) as "总人数"
from
(
    select
        amount_num,
        F_trans_buyer_user_id,
        count(F_trans_buyer_user_id) as meiren_bishu,
        sum(F_trans_amount) as total_amount,
        sum(F_business_cost_amount) as total_chengben,
        case when count(F_trans_buyer_user_id) = 1 then '1次'
             when count(F_trans_buyer_user_id) = 2 then '2次'
             when count(F_trans_buyer_user_id) = 3 then '3次'
             when count(F_trans_buyer_user_id) = 4 then '4次'
             when count(F_trans_buyer_user_id) = 5 then '5次'
             when count(F_trans_buyer_user_id) > 5 then '5次+'
        end as cishu
    from
    (
        select
            F_trans_buyer_user_id,
            F_trans_amount,
            F_business_cost_amount,
            case when F_trans_amount >= 0 and F_trans_amount <= 100000 then '1区间 0~1000'
                 when F_trans_amount > 100000 and F_trans_amount <= 500000 then '2区间 1001~5000'
                 when F_trans_amount > 500000 and F_trans_amount <= 1000000 then '3区间 5001~10000'
                 when F_trans_amount > 1000000 and F_trans_amount <= 3000000 then '4区间 10001~30000'
                 when F_trans_amount > 3000000 and F_trans_amount <= 5000000 then '5区间 3w~5w'
                 when F_trans_amount > 5000000 and F_trans_amount <= 10000000 then '6区间 5w~10w'
                 when F_trans_amount > 10000000 and F_trans_amount <= 50000000 then '7区间 10w~50w'
                 when F_trans_amount > 50000000 and F_trans_amount <= 100000000 then '8区间 50w~100w'
                 when F_trans_amount > 100000000 then '9区间 100w+'
             end as amount_num
        from t_wallet_info
        where F_recvable_recv_bank_id
        in (招行前端编码)
        and F_trans_seller_user_id
        in (理财场景商户UID)
        and F_business_time >= '2019-01-01 00:00:00'
        AND F_business_time <= '2019-07-30 23:59:59'
        AND F_business_type in (5,7,8)
    ) a
    group by amount_num,F_trans_buyer_user_id
) b
group by amount_num,cishu
order by amount_num,cishu;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值