赞
踩
with temp_1 as ( select distinct uid, imp_date from t_act_records where year(imp_date)=2020 ) ,temp_2 as( select uid, imp_date,row_number()over(partition by uid,month(imp_date) order by imp_date) rank from temp_1 ) ,temp_3 as( select uid,month(imp_date)as month,date_sub(imp_date,rank),count(1) as cnt from temp_2 group by 1,2,3) select month,uid,max(cnt) from temp_3 group by 1,2
with temp_1 as ( select distinct uid, imp_date from t_act_records where year(imp_date)=2020 ) ,temp_2 as( select uid, imp_date,lead(impt_date,1) over(partiton by month(impt_date),uid order by imp_date) 第二次登陆日期 from temp_1 ) ,temp_3 as ( select uid,month(impt_date),datediff(第二次登陆日期,imp_date) 差值 from temp_2 ) select month(imp_date),uid from temp_3 group by 1,2 having 差值=1
方法二
with temp_1 as ( select distinct uid, imp_date from t_act_records where year(imp_date)=2020 ) ,temp_2 as( select uid, imp_date,row_number()over(partition by uid,month(imp_date) order by imp_date) rank from temp_1 ) ,temp_3 as( select uid,month(imp_date)as month,date_sub(imp_date,rank) as diff from temp_2 ) select month,uid, from temp_3 group by 1,2 having count(diff)>2
with temp_1 as ( select distinct uid, imp_date from t_act_records where year(imp_date)=2020 ) ,temp_2 as( select uid, imp_date,row_number()over(partition by uid,month(imp_date) order by imp_date) rank from temp_1 ) ,temp_3 as( select uid,month(imp_date)as month,date_sub(imp_date,rank) as diff from temp_2 ) select month,count(distinct uid), from temp_3 group by 1 having count(diff)>5
–方法2
with temp_1 as (
select distinct uid, imp_date
from t_act_records
where year(imp_date)=2020
)
,temp_2 as(
select uid, imp_date,row_number()over(partition by uid,month(imp_date) order by imp_date) rank
from temp_1
)
,temp_3 as(
select u
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。