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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:55:34+00:00 2026-05-28T17:55:34+00:00

I have a table that has records in the form(simplified): ID (int), startTime(DateTime), endTime(DateTime)

  • 0

I have a table that has records in the form(simplified): ID (int), startTime(DateTime), endTime(DateTime)

I want to be able to group records that “overlap” time duration by minute.
Ex:

1 - 12.00.AM - 12.10.AM ( duration here is 10 min)
2 - 12.05.AM - 12.07.AM (duration here is 2 minutes but is overlapping with record ID = 1 in minutes 05, 06, 07)

The result of such a query should be 
minute 12.00 - record 1, 
minute 12.01 - record 1, 
... 
minute 12.05 - record 1 + record 2, 
minute 12.06 - record 1 + record 2, 
minute 12.07 - record 1 + record 2 
... 
minute 12.10 - record 1

Note I use sql server (2005 uppwards)

  • 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-28T17:55:36+00:00Added an answer on May 28, 2026 at 5:55 pm

    This is one way to do it in Oracle (11g Release 2 as it includes the LISTAGG function):

    with CTE as
           (    select STRT + (rownum - 1) / 24 / 60 as TIMES
                  from (select min(STARTTIME) as STRT from FORM1)
            connect by level <=
                         (select (max(ENDTIME) - min(STARTTIME)) * 24 * 60
                            from FORM1))
      select to_char(CTE.TIMES, 'hh24:mi') as MINUTE
            ,LISTAGG(ID, ',') within group (order by ID) as IDS
        from   CTE
             join
               FORM1
             on CTE.TIMES <= FORM1.ENDTIME and CTE.TIMES >= FORM1.STARTTIME
    group by to_char(CTE.TIMES, 'hh24:mi')
    order by to_char(CTE.TIMES, 'hh24:mi')
    

    The test data I used was:

    create table FORM1
    (
      ID          number
     ,STARTTIME   date
     ,ENDTIME     date
    );
    
    insert into FORM1
         values (
                  1
                 ,to_date('26/01/2012 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
                 ,to_date('26/01/2012 00:10:00', 'dd/mm/yyyy hh24:mi:ss'));
    
    insert into FORM1
         values (
                  2
                 ,to_date('26/01/2012 00:05:00', 'dd/mm/yyyy hh24:mi:ss')
                 ,to_date('26/01/2012 00:07:00', 'dd/mm/yyyy hh24:mi:ss'));
    

    And I get the following result:

    Minute  IDs
    00:00   1
    00:01   1
    00:02   1
    00:03   1
    00:04   1
    00:05   1,2
    00:06   1,2
    00:07   1,2
    00:08   1
    00:09   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 that has records with a structure similar to this.. ID
I have one table that has sales records and another table that has additional
I have a table that has 8 million records, with many fields, including lat/long
I have a table that has millions of records and we are looking at
I have a table that has about 1/2 million records in it. Each month
I have a table within my database that has many records, some records share
I have a table name Discount that has the following schema: PK DiscountID int
I have table that shows some records from database. each table has a column
I have a table that has a processed_timestamp column -- if a record has
Background I have a dimension table that has a single record for each day.

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.