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 8627319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:14:56+00:00 2026-06-12T08:14:56+00:00

sorry if my title doesn’t properly describe what task I’m trying to perform. For

  • 0

sorry if my title doesn’t properly describe what task I’m trying to perform.

For a university project, I have received the access logs of a website, I have discarded the unneeded columns and condensed it down to this:

╔══════════╦══════════════════════╦═════════════════╦═════════════╦════════════════╗
║ accessid ║ date_time_in_seconds ║ yg_requester_id ║ referent_id ║ referent_docid ║
╠══════════╬══════════════════════╬═════════════════╬═════════════╬════════════════╣
║     2449 ║        2009011621830 ║           32276 ║       12648 ║              1 ║
║     2776 ║        2009011622726 ║           76360 ║       11070 ║              1 ║
║     2804 ║        2009011622783 ║           32276 ║       13845 ║              1 ║
║     2894 ║        2009011623025 ║           32276 ║        7222 ║              1 ║
║     2895 ║        2009011623037 ║           32276 ║        1530 ║              1 ║
║     3000 ║        2009011623406 ║           32276 ║        3728 ║              1 ║
║     3019 ║        2009011623497 ║          520060 ║       10356 ║              1 ║
║     3245 ║        2009011625780 ║          300841 ║        4607 ║              1 ║
║     3274 ║        2009011628309 ║          532664 ║       14377 ║              1 ║
║     3275 ║        2009011628420 ║          532664 ║        9097 ║              1 ║
╚══════════╩══════════════════════╩═════════════════╩═════════════╩════════════════╝

Originally the time and datestamps were in seperate columns per unit of measurement (year, month, day, hour, minute, second) and for the purposes of easier calculation, I have consolidated them into date_time_in_seconds which has the format

[0000][00][00][00000]
[YEAR][MONTH][DAY][Number of Seconds since 00:00]

accessid is the table entry ID, yg_requester_id is the unique id of the website visitor, referent_id is the ID of the web site article they read, referent_docid denotes the type of article, however is not needed in this task.

Basically, I would like to be able to find the time difference since the last different referent_id was accessed by the same yg_requester_id.
So for instance, looking at this section of rows from the above table:

╔══════════╦══════════════════════╦═════════════════╦═════════════╦════════════════╗
║ accessid ║ date_time_in_seconds ║ yg_requester_id ║ referent_id ║ referent_docid ║
╠══════════╬══════════════════════╬═════════════════╬═════════════╬════════════════╣
║     2449 ║        2009011621830 ║           32276 ║       12648 ║              1 ║
║     2776 ║        2009011622726 ║           76360 ║       11070 ║              1 ║
║     2804 ║        2009011622783 ║           32276 ║       13845 ║              1 ║
╚══════════╩══════════════════════╩═════════════════╩═════════════╩════════════════╝

yg_requester_id 32276 accessed the article with id 12648 at 06:03:50 (21830 seconds after midnight) on the 16th of January 2009. They then accessed the article with id 13845 at 06:19:43 (22783 seconds after midnight) on the 16th January 2009. So it is safe to assume that the user read the first article (id 12648) for about 15 minutes and 50 seconds

What I would like to find is that time difference between the articles accessed by the same user. Consecutive articles read by a user may not have consecutive accessid’s (although it will always increment). I would also like to limit the time read to about an hour as the task is to filter out records where the time read is under a variable number of minutes (15 for instance).

Thanks in advance, let me know if any more information is needed

  • 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-06-12T08:14:57+00:00Added an answer on June 12, 2026 at 8:14 am

    I would use ROW_NUMBER partitioning the resultset by yg_requester_id and ordering it by either accessid or datetime (supposing you are going to change your date_time_in_seconds column into a regular datetime column, as suggested in the comments.
    Then I would join the resultset with itself by requester and to the previous record, and get the difference.

    Let me try to write the query without having the proper data:

    SELECT X1.yg_requester_id, DATEDIFF(SECOND, X1.NewDateTimeField, X2.NewDateTimeField) AS TimeDifferenceInSeconds, X1.referent_id AS NewArticle, X2.referent_id AS FormerArticle
    FROM
    (
    SELECT ROW_NUMBER() OVER(PARTITION BY yg_requester_id ORDER BY NewDateTimeField DESC) AS Position, NewDateTimeField, yg_requester_id, referent_id
    FROM YourTable
    
    ) X1
    INNER JOIN 
    (
    SELECT ROW_NUMBER() OVER(PARTITION BY yg_requester_id ORDER BY NewDateTimeField DESC) AS Position, NewDateTimeField, yg_requester_id, referent_id
    FROM YourTable  
    ) X2 ON X2.yg_requester_id = X1.yg_requester_id AND X2.Position = X1.Position - 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sorry if this title doesn't describe the problem properly but I wasn't sure
Sorry if the title doesn't make sense. Basically I have a series of strings
Sorry if the title doesn't make much sense, if you have a suggestion on
Sorry the title may not be very clear. Basically I have a wrapper for
Sorry about the title, I couldn't think of a better way to describe the
Sorry for dodgy title, couldn't think of anything better... Anyway, I have written a
Sorry about the title — wasn’t sure how to word it. Basically I have
Sorry about the strange title. I really have no idea how to express it
My question title isn't clear, sorry. I tried ;) I have a binary string
Sorry if that title doesn't make sense, I'm new to Rails and I'm building

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.