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.79.3 1301654354
180.2.79.3 1301654356
180.2.79.3 1301654358
180.2.79.3 1301654366
180.2.79.3 1301654368
180.2.79.3 1301654422
I have a query to get total tracks:
SELECT COUNT(*) AS tracks FROM tracking
However, I now want to disregard visits from users that have visited multiple times within 10 seconds of each visit. Since I don’t consider this another visit, its still part of the first visit.
When the ip_address is the same, check
timestamp and only count those rows
that are 10 seconds away from each
other.
I am having difficulty in putting this into a SQL query form, I would appreciate any help on this!
Let me start with this table. I’ll use ordinary timestamps so we can easily see what’s going on.
If I understand you correctly, you want to count these like this.
You can do that for each ip_address by selecting the maximum timestamp that is both
timestamp, and
Taking these two criteria together will introduce some nulls, which turn out to be really useful.
The timestamp that marks the end of a visit has a null for its own next_page. That’s because no timestamp is less than or equal to time_stamp + 10 seconds for that row.
To get a count, I’d probably create a view and count the nulls.