create table users(
uid int,
dt string);
select uid,pdt,count(uid) as cnt_day
from(select t1.uid,date_sub(t1.dt,t1.rm) as pdt
from
(select uid,dt,
row_number() over(distribute by uid sort by dt) rm
from (select uid,dt from users group by uid,dt)m) t1)t2
group by uid,pdt;
对打点表中的用户计算连续登录天数
date_sub(t1.dt,t1.rm) 在t1.dt的基础上减去 t1.rm的天数,rm是按照差值为1递增的,所以如果得到的pdt值相同的同一个uid值,说明为用户连续登录的天数,但是这里的pdt值仅作为这个统计,没有其他意义
连续登录天数大于7天的用户
select uid,pdt
from(select t1.uid,date_sub(t1.dt,t1.rm) as pdt
from
(select uid,dt,
row_number() over(distribute by uid sort by dt) rm
from (select uid,dt from users group by uid,dt)m) t1)t2
group by uid,pdt having count(uid)>6;