1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
select distinct user_id, date(visit_time) as dt from cm.tb_user_logs;
select *, row_number() over (PARTITION by user_id order by dt) as xrank from (select distinct user_id, date(visit_time) as dt from cm.tb_user_logs) a;
select *, date_sub(dt, INTERVAL xrank DAY) as delta from (select *, row_number() over (PARTITION by user_id order by dt) as xrank from (select distinct user_id, date(visit_time) as dt from cm.tb_user_logs) a ) b;
select user_id, min(dt) as start_date, count(*) as days from (select *, date_sub(dt, INTERVAL xrank DAY) as delta from (select *, row_number() over (PARTITION by user_id order by dt) as xrank from (select distinct user_id, date(visit_time) as dt from cm.tb_user_logs) a ) b ) c GROUP BY user_id, delta having count(*) >= 3;
|