hive-sql 连续登录五天的用户
with tmp as (
select '梁牧泽' as uid, '2023-03-03' as `dt` union all
select '梁牧泽' as uid, '2023-03-04' as `dt` union all
select '梁牧泽' as uid, '2023-03-05' as `dt` union all
select '梁牧泽' as uid, '2023-03-07' as `dt` union all
select '梁牧泽' as uid, '2023-03-08' as `dt` union all
select '梁牧泽' as uid, '2023-03-09' as `dt` union all
select '梁牧泽' as uid, '2023-03-10' as `dt` union all
select '梁牧泽' as uid, '2023-03-11' as `dt` union all
select '梁牧泽' as uid, '2023-03-12' as `dt` union all
select '夏初' as uid, '2023-03-10' as `dt` union all
select '夏初' as uid, '2023-03-10' as `dt` union all
select '夏初' as uid, '2023-03-11' as `dt` union all
select '夏初' as uid, '2023-03-12' as `dt` union all
select '夏初' as uid, '2023-03-13' as `dt` union all
select '夏初' as uid, '2023-03-14' as `dt` union all
select '夏初' as uid, '2023-03-15' as `dt`
)
select
uid,
dt,
follow_5_dt
from
(select uid,dt
,last_value(dt) over(partition by uid order by dt asc rows between current row and 4 following) as follow_5_dt
,datediff(last_value(dt) over(partition by uid order by dt asc rows between current row and 4 following),dt) as diff_day
from tmp ) t where diff_day=4
结果: