drop table if exists analytic.rfm_1_max_avg_measures_detail;create table analytic.rfm_1_max_avg_measures_detail as select member_id,datediff('day',date(max(sale_time)),sysdate) as sale_day_range,count(member_id) as sum_buy_times,sum(single_amount) as sum_amtfrom xxx where sale_time>='2022-01-01' and valid_falg='1' group by 1;<\/code><\/pre>\n\n\n\n
drop table if exists analytic.rfm_1_max_avg_measures;create table analytic.rfm_1_max_avg_measures as select avg(sale_day_range) as avg_sale_day_range,avg(sum_buy_times) as avg_buy_times,avg(sum_amt) as avg_amt from analytic.rfm_1_max_avg_measures_detail;<\/code><\/pre>\n\n\n\n
drop table if exists analytic.rfm_1_member_apart;\ncreate table analytic.rfm_1_member_apart as \nselect \n t1.member_id,t1.sale_day_range\n,t1.sum_buy_times,t1.sum_amt\n,t2.avg_sale_date,t2.avg_buy_time,t2.avg_amt\n,case when t1.sale_day_range<=t2.avg_sale_day_range\n then '1' else '0' end as rfm_r\n,case when t1.sum_buy_times>=t2.avg_buy_times\n then '1' else '0' end as rfm_f\n,case when t1.sum_amt>=t2.avg_amt \n then '1' else '0' end as rfm_m\nfrom analytic.rfm_1_max_avg_measures_detail t1\ncross join analytic.rfm_1_max_avg_measures t2;<\/code><\/pre>\n\n\n\n