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

后端 未结 8 616
情歌与酒
情歌与酒 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:51

    The simplest way to do this is to divide the timestamps by 10, and count the distinct combinations of those values and the ip_address values. That way each 10 second period is counted separately.

    If you run this on your sample data it will give you 4 tracks, which is what you want I think.

    Give it a try and see if it gives you the desired results on your full data set:

    SELECT COUNT(DISTINCT ip_address, FLOOR(time_stamp/10)) AS tracks 
    FROM tracking
    

提交回复
热议问题