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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:54:30+00:00 2026-05-14T01:54:30+00:00

I have a table in an Oracle Database that has, among others, a DATE

  • 0

I have a table in an Oracle Database that has, among others, a DATE column that is loaded with the insertion timestamp of each row. I need to use existing data in such table to analyze the correlation between some events, so that with data like this:

COL_1         COL_2         TS
    A             1         Mon 15, February 2010 10:03:22
    B             2         Mon 15, February 2010 10:05:37
    C             3         Mon 15, February 2010 10:20:21
    D             4         Mon 15, February 2010 10:20:21
    E             5         Mon 15, February 2010 10:20:24
    F             6         Mon 15, February 2010 10:23:35
    G             7         Mon 15, February 2010 10:45:22

I would like to correlate to something like this, assumming related records are between a 5-minutes max difference between current and next “TS”:

FIRST_TS                            COUNT
Mon 15, February 2010 10:03:22          2
Mon 15, February 2010 10:20:21          4
Mon 15, February 2010 10:45:22          1

Is is possible to use analytic functions to achieve this? How?

  • 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-14T01:54:30+00:00Added an answer on May 14, 2026 at 1:54 am

    This will group together rows that are less than 5 minutes distant from the previous row:

    --ALTER SESSION SET nls_date_format= 'dy dd, month yyyy hh24:mi:ss';
    --ALTER SESSION SET nls_date_language='ENGLISH';
    SQL> WITH DATA AS (
      2  SELECT to_date('Mon 15, February 2010 10:03:22') ts FROM dual
      3  UNION ALL SELECT to_date('Mon 15, February 2010 10:05:37') FROM dual
      4  UNION ALL SELECT to_date('Mon 15, February 2010 10:20:21') FROM dual
      5  UNION ALL SELECT to_date('Mon 15, February 2010 10:20:21') FROM dual
      6  UNION ALL SELECT to_date('Mon 15, February 2010 10:20:24') FROM dual
      7  UNION ALL SELECT to_date('Mon 15, February 2010 10:23:35') FROM dual
      8  UNION ALL SELECT to_date('Mon 15, February 2010 10:45:22') FROM dual
      9  )
     10  SELECT MIN(ts) first_ts, COUNT(*) COUNT
     11    FROM (SELECT ts, SUM(gap) over(ORDER BY ts) ts_group
     12             FROM (SELECT ts,
     13                           CASE
     14                              WHEN ts - lag(ts) over(ORDER BY ts)
     15                                    <= 5 / (60 * 24) THEN
     16                               0
     17                              ELSE
     18                               1
     19                           END gap
     20                      FROM DATA))
     21  GROUP BY ts_group;
    
    FIRST_TS                              COUNT
    -------------------------------- ----------
    mon 15, february  2010 10:03:22           2
    mon 15, february  2010 10:20:21           4
    mon 15, february  2010 10:45:22           1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have this table in an Oracle DB which has a primary key defined
I have an entity that maps to an external oracle table which is one
Say I have an Oracle PL/SQL block that inserts a record into a table
I have an Oracle table which contains event log messages for an application. We
I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100
I'll simplify the problem as much as possible: I have an oracle table: row_priority,
I have an Access 2002 application which links an Oracle table via ODBC with
I have table inside a div tab. The table has 40 rows in it
I am using Hibernate in Spring MVC 3.05 and an Oracle database. I have

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.