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

  • Home
  • SEARCH
  • 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 238043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:28:27+00:00 2026-05-11T20:28:27+00:00

site_id | start_date | end_date 1 | oct 1, 08 | oct 2, 08

  • 0
site_id | start_date | end_date
      1 | oct  1, 08 | oct  2, 08
      1 | oct  2, 08 | oct  3, 08
 ...
      1 | oct 30, 08 | oct 31, 08
      2 | oct  1, 08 | oct  2, 08
      2 | oct  2, 08 | oct  3, 08
 ...
      2 | oct 30, 08 | oct 31, 08

I have a table that contains 1 record per site per day of the month (per month of the year). I need to be able to determine if a site for a given month has at least 15 contiguous records, and I need to know the start and end date of that series of contiguous days. I can do this in a stored procedure, but I was hoping this could be accomplished in a single query. I am dealing with a fairly large dataset, at least 30 million records per month.

Example Results:

site_id | contiguous_start_date | contiguous_end_date
      1 | oct 5, 2008           | oct 20, 2008
      2 | oct 10                | oct 30, 2008
      3 | oct 1                 | oct 31, 2008 

thanks for your help!

  • 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-11T20:28:27+00:00Added an answer on May 11, 2026 at 8:28 pm

    Here is an example of how to do such a query:

    SQL> create table t (site_id,start_date,end_date)
      2  as
      3  select 1, date '2008-10-01', date '2008-10-02' from dual union all
      4  select 1, date '2008-10-02', date '2008-10-03' from dual union all
      5  select 1, date '2008-10-03', date '2008-10-30' from dual union all
      6  select 1, date '2008-10-30', date '2008-10-31' from dual union all
      7  select 2, date '2008-10-01', date '2008-10-02' from dual union all
      8  select 2, date '2008-10-02', date '2008-10-03' from dual union all
      9  select 2, date '2008-10-03', date '2008-10-04' from dual union all
     10  select 2, date '2008-10-04', date '2008-10-05' from dual union all
     11  select 2, date '2008-10-05', date '2008-10-06' from dual union all
     12  select 2, date '2008-10-06', date '2008-10-07' from dual union all
     13  select 2, date '2008-10-07', date '2008-10-08' from dual union all
     14  select 2, date '2008-10-08', date '2008-10-09' from dual union all
     15  select 2, date '2008-10-09', date '2008-10-10' from dual union all
     16  select 2, date '2008-10-10', date '2008-10-11' from dual union all
     17  select 2, date '2008-10-11', date '2008-10-12' from dual union all
     18  select 2, date '2008-10-12', date '2008-10-13' from dual union all
     19  select 2, date '2008-10-13', date '2008-10-14' from dual union all
     20  select 2, date '2008-10-14', date '2008-10-15' from dual union all
     21  select 2, date '2008-10-15', date '2008-10-16' from dual union all
     22  select 2, date '2008-10-16', date '2008-10-17' from dual union all
     23  select 2, date '2008-10-17', date '2008-10-18' from dual union all
     24  select 2, date '2008-10-18', date '2008-10-19' from dual union all
     25  select 2, date '2008-10-19', date '2008-10-20' from dual union all
     26  select 3, date '2008-10-01', date '2008-10-02' from dual union all
     27  select 3, date '2008-10-02', date '2008-10-03' from dual union all
     28  select 3, date '2008-10-03', date '2008-10-04' from dual union all
     29  select 3, date '2008-10-04', date '2008-10-05' from dual union all
     30  select 3, date '2008-10-05', date '2008-10-06' from dual union all
     31  select 3, date '2008-10-06', date '2008-10-07' from dual union all
     32  select 3, date '2008-10-07', date '2008-10-08' from dual union all
     33  select 3, date '2008-10-08', date '2008-10-09' from dual union all
     34  select 3, date '2008-10-09', date '2008-10-10' from dual union all
     35  select 3, date '2008-10-30', date '2008-10-31' from dual
     36  /
    
    Tabel is aangemaakt.
    

    And then the query:

    SQL> select site_id
      2       , min(start_date) contiguous_start_date
      3       , max(end_date) contiguous_end_date
      4       , count(*) number_of_contiguous_records
      5    from ( select site_id
      6                , start_date
      7                , end_date
      8                , max(rn) over (partition by site_id order by start_date) maxrn
      9             from ( select site_id
     10                         , start_date
     11                         , end_date
     12                         , case lag(end_date) over (partition by site_id order by start_date)
     13                             when start_date then null
     14                             else rownum
     15                           end rn
     16                      from t
     17                  )
     18          )
     19   group by site_id
     20       , maxrn
     21   order by site_id
     22       , contiguous_start_date
     23  /
    

    And the results:

       SITE_ID CONTIGUOUS_START_DA CONTIGUOUS_END_DATE NUMBER_OF_CONTIGUOUS_RECORDS
    ---------- ------------------- ------------------- ----------------------------
             1 01-10-2008 00:00:00 31-10-2008 00:00:00                            4
             2 01-10-2008 00:00:00 20-10-2008 00:00:00                           19
             3 01-10-2008 00:00:00 10-10-2008 00:00:00                            9
             3 30-10-2008 00:00:00 31-10-2008 00:00:00                            1
    
    4 rijen zijn geselecteerd.
    

    Regards,
    Rob.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a couple of variants of a rename command,… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer There is currently no way to build CLS-compliant assemblies from… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer You might want to look at Google Protocol Buffers or… May 12, 2026 at 12:33 pm

Related Questions

OK, I have just been reading and trying for the last hour to import
I'm developing a new site, and I have to make private messages for our
I am using the following query to find out to top 6 viewed pages
I have a table containing pagehit (normalized) data and I need to grab the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.