Find entries of 20 or more by contact within one minute of each entry

后端 未结 2 1644
终归单人心
终归单人心 2021-01-29 12:57

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

2条回答
  •  遇见更好的自我
    2021-01-29 13:35

    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.

提交回复
热议问题