hive 最长连续登陆天数讲解

hive 最长连续登陆天数讲解_第1张图片
UID loadtime
201 3
202 4
203 2

思路 第一步
2017-01-01 1
2017-01-02 2
2017-01-04 3
2017-01-05 4
2017-01-06 5

select uid,
loadtime,
row_number()over(partition by uid order by loadtime asc) r
from user

思路第二步、
2016-12-31
2016-12-31
2017-01-01
2017-01-01
2017-01-01

select b.uid,max(n)
(select
b.uid,
count(1) n
from
(select a.uid,
a.loadtime
date_sub(a.laodtime,r)
from
(select uid,
loadtime,
row_number()over(partition by uid order by loadtime asc) r
from user) a)b
group by b.uid,b.s) c
group by c.uid

你可能感兴趣的:(hive 最长连续登陆天数讲解)