-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1454.sql
More file actions
32 lines (27 loc) · 710 Bytes
/
1454.sql
File metadata and controls
32 lines (27 loc) · 710 Bytes
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
with
distinct_id_loginDate as (
select distinct id, login_date
from Logins
),
count_consecutive_days_after as (
select distinct
t1.id
from
distinct_id_loginDate t1
inner join distinct_id_loginDate t2
on (
t1.id = t2.id
and datediff(t2.login_date, t1.login_date) < 5
and datediff(t2.login_date, t1.login_date) >= 0
)
group by t1.id, t1.login_date
having count(*) >= 5
)
select
a.id,
a.name
from
Accounts a
inner join count_consecutive_days_after l
using(id)
order by a.id