Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4256030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:17:53+00:00 2026-05-21T05:17:53+00:00

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

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:17:54+00:00Added an answer on May 21, 2026 at 5:17 am

    Let me start with this table. I’ll use ordinary timestamps so we can easily see what’s going on.

    180.2.79.3   2011-01-01 08:00:00
    180.2.79.3   2011-01-01 08:00:09
    180.2.79.3   2011-01-01 08:00:20
    180.2.79.3   2011-01-01 08:00:23
    180.2.79.3   2011-01-01 08:00:25
    180.2.79.3   2011-01-01 08:00:40
    180.2.79.4   2011-01-01 08:00:00
    180.2.79.4   2011-01-01 08:00:13
    180.2.79.4   2011-01-01 08:00:23
    180.2.79.4   2011-01-01 08:00:25
    180.2.79.4   2011-01-01 08:00:27
    180.2.79.4   2011-01-01 08:00:29
    180.2.79.4   2011-01-01 08:00:50
    

    If I understand you correctly, you want to count these like this.

    180.2.79.3   3
    180.2.79.4   3
    

    You can do that for each ip_address by selecting the maximum timestamp that is both

    • greater than the current row’s
      timestamp, and
    • less than or equal to 10 seconds greater than the current row’s timestamp.

    Taking these two criteria together will introduce some nulls, which turn out to be really useful.

    select ip_address, 
           t_s.time_stamp, 
           (select max(t.time_stamp) 
            from t_s t 
            where t.ip_address = t_s.ip_address 
              and t.time_stamp > t_s.time_stamp
              and t.time_stamp - t_s.time_stamp <= interval '10' second) next_page
    from t_s 
    group by ip_address, t_s.time_stamp
    order by ip_address, t_s.time_stamp;
    
    ip_address   time_stamp            next_page
    180.2.79.3   2011-01-01 08:00:00   2011-01-01 08:00:09
    180.2.79.3   2011-01-01 08:00:09   <null>
    180.2.79.3   2011-01-01 08:00:20   2011-01-01 08:00:25
    180.2.79.3   2011-01-01 08:00:23   2011-01-01 08:00:25
    180.2.79.3   2011-01-01 08:00:25   <null>
    180.2.79.3   2011-01-01 08:00:40   <null>
    180.2.79.4   2011-01-01 08:00:00   <null>
    180.2.79.4   2011-01-01 08:00:13   2011-01-01 08:00:23
    180.2.79.4   2011-01-01 08:00:23   2011-01-01 08:00:29
    180.2.79.4   2011-01-01 08:00:25   2011-01-01 08:00:29
    180.2.79.4   2011-01-01 08:00:27   2011-01-01 08:00:29
    180.2.79.4   2011-01-01 08:00:29   <null>
    180.2.79.4   2011-01-01 08:00:50   <null>
    

    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.

    select ip_address, count(*)
    from t_s_visits 
    where next_page is null
    group by ip_address
    
    180.2.79.3   3
    180.2.79.4   3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to keep track of the number of visitors to a web page.
I need to Track Unique Visitor count in my web application. I would really
To track user activity history on a web application, I am attempting to save
I have a xml web service which I would like to track using Google
We want to track the time taken by a web service call between a
my goal is to track all logged users in my web portal to develop
I'm trying to track an event in my app using Yahoo Web Analytics. The
I started using git to track my customizations to a 3rd party web app.
I have a web service which allows the users to upload and keep track
I am searching for the best way for track user on a web site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.