We are collecting some analytics data for contacts & each page they visit. A lot of the analytics data is from malicious attacks or bots, so they are hitting like 20+ pages
You can get contacts that visited 20 pages within a minute using lag()
:
select distinct contactid
from (select t.*,
lag(datecreated, 19) over (partition by contactid order by datecreated) as lag20
from t
) t
where lag20 > dateadd(minute, -1, datecreated);
That is, there are 20 rows within a minute if you look back 19 rows and that row is less than a minute before the current row.