Count number of rows that are not within 10 seconds of each other

后端 未结 8 615
情歌与酒
情歌与酒 2021-02-01 09:26

I track web visitors. I store the IP address as well as the timestamp of the visit.

ip_address    time_stamp
180.2.79.3  1301654105
180.2.79.3  1301654106
180.2.         


        
8条回答
  •  悲哀的现实
    2021-02-01 09:53

    Select Z.IP, Count(*) As VisitCount
    From    (
            Select V.IP
            From visitors As V
                Left Join visitors As V2
                    On V2.IP = V.IP
                        And V2.time_stamp > V.time_stamp
            Group By V.IP, V.time_stamp
            Having (Min(V2.time_stamp) - V.time_stamp) >= 10
            ) As Z
    Group By Z.IP
    

    This counts any visit where the next entry is more than 10 seconds away as a new visit.

提交回复
热议问题