oracle数据回流,Oracle-利用解析函数计算连续、回流

---最大连续交易天数

select t2.customer_no,max(t2.co)

from

(select

t1.customer_no,t1.yp-t1.rn rk,count(1) co

from (select ctd.customer_no,

ctd.order_time yp,

row_number() over(partition by ctd.customer_no order by ctd.order_time) rn

from posp_boss.customer_trans_day ctd

where ctd.order_time >= to_date('20180101', 'yyyymmdd')

order by ctd.customer_no,ctd.order_time)t1

group by t1.customer_no,t1.yp-t1.rn)t2

group by t2.customer_no

---计算回流状况

with t1 as

(select ctd.customer_no,

ctd.order_time yp,

row_number() over(partition by ctd.customer_no order by ctd.order_time) rn

from posp_boss.customer_trans_day ctd

where ctd.order_time >= to_date('20180101', 'yyyymmdd')

order by ctd.customer_no,ctd.order_time)

select t1.customer_no,max(ceil(t2.yp-t1.yp)) ypc

from

(select t1.customer_no,t1.yp,t1.rn-1 rm

from t1) t2

left join t1 on t1.customer_no = t2.customer_no and t1.rn = t2.rm

group by t1.customer_no

---计算回流涉及天数,商户,交易量

with t1 as

(select ctd.customer_no,

ctd.order_time yp,

row_number() over(partition by ctd.customer_no order by ctd.order_time) rn

from posp_boss.customer_trans_day ctd

where ctd.order_time >= to_date('20180101', 'yyyymmdd')

order by ctd.customer_no,ctd.order_time)

select

t3.ypc,

count(distinct t3.customer_no) mt,

sum(t4.amt) amount

from

(select t1.customer_no,max(ceil(t2.yp-t1.yp)) ypc

from

(select t1.customer_no,t1.yp,t1.rn-1 rm

from t1) t2

left join t1 on t1.customer_no = t2.customer_no and t1.rn = t2.rm

group by t1.customer_no)t3

join

(select ctd.customer_no,

sum(ctd.trans_amount) amt

from posp_boss.customer_trans_day ctd

where ctd.order_time >= to_date('20180101', 'yyyymmdd')

group by ctd.customer_no)t4 on t3.customer_no = t4.customer_no

group by t3.ypc

标签:customer,no,t1,ctd,time,Oracle,回流,解析,order

来源: https://www.cnblogs.com/daoren/p/10461615.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值