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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:40:58+00:00 2026-05-19T03:40:58+00:00

I have a table with the following columns: contactId (int) interval (int) date (smalldate)

  • 0

I have a table with the following columns:

contactId  (int)  
interval   (int)  
date (smalldate)  

small sample data:

1,120,'12/02/2010'  
1,121,'12/02/2010'  
1,122,'12/02/2010'  
1,123,'12/02/2010'  
1,145,'12/02/2010'  
1,146,'12/02/2010'  
1,147,'12/02/2010'  
2,122,'12/02/2010'  
2,123,'12/02/2010'  
2,124,'12/02/2010'  
2,320,'12/02/2010'  
2,321,'12/02/2010'  
2,322,'12/02/2010'  
2,450,'12/02/2010'  
2,451,'12/02/2010'  

how/is it possible – to get sql to return columns “contactId, minInterval, maxInterval, date”, e.g

1,120,123,'12/02/2010'  
1,145,147,'12/02/2010'  
2,122,124,'12/02/2010'  
2,320,322,'12/02/2010'  
2,450,451,'12/02/2010'  

hopefully this makes sense, basically i’m looking to figure out the min/max range of the intervals by provider & date for the range where they increment by one… once there is a break in the interval incrementer (e.g. more than one) then it would indicate a new min/max range…

any help is greatly appreciated 🙂

here is my exact SQL table setup:

create table availability  
(  
 Id  (int)  
 ProviderId (int)  
 IntervalId (int)  
 Date (date)  
)  

sample data

providerid,intervalid,date  
1128,108,2010-12-27  
1128,109,2010-12-27  
1128,110,2010-12-27  
1128,111,2010-12-27  
1128,112,2010-12-27  
1128,113,2010-12-27  
1128,114,2010-12-27  
1128,120,2010-12-27  
1128,121,2010-12-27  
1128,122,2010-12-27  
1128,123,2010-12-27  
1128,124,2010-12-27  
1128,125,2010-12-27  
1213,108,2010-12-27  
1213,109,2010-12-27  
1213,110,2010-12-27  
1213,111,2010-12-27  
1213,112,2010-12-27  
1213,113,2010-12-27  
1213,114,2010-12-27  
1213,115,2010-12-27  
1213,232,2010-12-27  
1213,233,2010-12-27  
1213,234,2010-12-27  
3954,198,2010-12-27  
3954,199,2010-12-27  
3954,200,2010-12-27  
3954,201,2010-12-27   
3954,202,2010-12-27  
3954,203,2010-12-27   
3954,204,2010-12-27  
3954,205,2010-12-27  
3954,206,2010-12-27  
3954,207,2010-12-27  
3954,208,2010-12-27  
3954,209,2010-12-27  
3954,210,2010-12-27  
3954,211,2010-12-27  
3954,212,2010-12-27  
3954,213,2010-12-27  
3954,214,2010-12-27  
3954,215,2010-12-27  
3954,216,2010-12-27  
3954,217,2010-12-27  
3954,218,2010-12-27  
3954,229,2010-12-27  
3954,230,2010-12-27  
3954,231,2010-12-27  
3954,232,2010-12-27  
3954,233,2010-12-27  
3954,234,2010-12-27  
1128,108,2010-12-28  
1128,109,2010-12-28  
1128,110,2010-12-28  
1128,111,2010-12-28  
1128,112,2010-12-28  
1128,113,2010-12-28  
1128,114,2010-12-28  
1128,115,2010-12-28  
1128,116,2010-12-28  
3954,186,2010-12-28  
3954,187,2010-12-28  
3954,188,2010-12-28  
3954,189,2010-12-28  
3954,190,2010-12-28  
3954,213,2010-12-28  
3954,214,2010-12-28  
3954,215,2010-12-28  
3954,216,2010-12-28  
3954,217,2010-12-28  
3954,218,2010-12-28  
3954,219,2010-12-28  
3954,220,2010-12-28  
3954,221,2010-12-28  
3954,222,2010-12-28  

sample result using current sql within answers:

1062,180,180,2010-12-20  
1062,179,179,2010-12-20  
1062,178,178,2010-12-20  
1062,177,177,2010-12-20  
1062,176,176,2010-12-20  
1062,175,175,2010-12-20  
1062,174,174,2010-12-20  
1062,173,173,2010-12-20  
1062,172,172,2010-12-20  
1062,171,171,2010-12-20  
1062,170,170,2010-12-20  
1062,169,169,2010-12-20    
1062,168,168,2010-12-20  
1062,167,167,2010-12-20  
1062,166,166,2010-12-20  
1062,165,165,2010-12-20  
1062,164,164,2010-12-20  
1062,163,163,2010-12-20  
1062,162,162,2010-12-20  
1062,161,161,2010-12-20  
1062,160,160,2010-12-20  
1062,159,159,2010-12-20  
1062,158,158,2010-12-20  
1062,157,157,2010-12-20  
1062,156,156,2010-12-20  
1062,155,155,2010-12-20  
1062,154,154,2010-12-20  
1062,153,153,2010-12-20  
1062,152,152,2010-12-20  
1062,151,151,2010-12-20  
1062,150,150,2010-12-20  
1062,149,149,2010-12-20  
1062,148,148,2010-12-20  
1062,147,147,2010-12-20  
1062,146,146,2010-12-20  
1062,145,145,2010-12-20  
1062,144,144,2010-12-20  
1062,143,143,2010-12-20  
1062,142,142,2010-12-20  
1062,141,141,2010-12-20  
1062,140,140,2010-12-20  
1062,139,139,2010-12-20  
1062,138,138,2010-12-20  
1062,137,137,2010-12-20  
1062,136,136,2010-12-20  
1062,135,135,2010-12-20  
1062,134,134,2010-12-20  
1062,133,133,2010-12-20  
1062,132,132,2010-12-20  
1062,131,131,2010-12-20  
1062,130,130,2010-12-20  
1062,129,129,2010-12-20  
1062,128,128,2010-12-20  
1062,127,127,2010-12-20  
1062,126,126,2010-12-20  
1062,125,125,2010-12-20  
1062,124,124,2010-12-20  
1062,123,123,2010-12-20  
1062,122,122,2010-12-20  
1062,121,121,2010-12-20  
1062,120,120,2010-12-20  
1062,119,119,2010-12-20  
1062,118,118,2010-12-20  
1062,117,117,2010-12-20  
1062,116,116,2010-12-20  
1062,115,115,2010-12-20  
1062,114,114,2010-12-20  
1062,113,113,2010-12-20  
1062,112,112,2010-12-20  
  • 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-19T03:40:58+00:00Added an answer on May 19, 2026 at 3:40 am

    In SQL Server, Oracle and PostgreSQL:

    WITH    q AS
            (
            SELECT  t.*, interval - ROW_NUMBER() OVER (PARTITION BY contactID, date ORDER BY interval) AS sr
            FROM    mytable t
            )
    SELECT  contactID, date, MIN(interval), MAX(interval)
    FROM    q
    GROUP BY
            date, contactID, sr
    ORDER BY
            date, contactID, sr
    

    Update:

    With your test data I get this output:

    WITH    mytable (providerId, intervalId, date) AS
            (
            SELECT  1128,108,'2010-12-27' UNION ALL
            SELECT  1128,109,'2010-12-27' UNION ALL
            SELECT  1128,110,'2010-12-27' UNION ALL
            SELECT  1128,111,'2010-12-27' UNION ALL
            SELECT  1128,112,'2010-12-27' UNION ALL
            SELECT  1128,113,'2010-12-27' UNION ALL
            SELECT  1128,114,'2010-12-27' UNION ALL
            SELECT  1128,120,'2010-12-27' UNION ALL
            SELECT  1128,121,'2010-12-27' UNION ALL
            SELECT  1128,122,'2010-12-27' UNION ALL
            SELECT  1128,123,'2010-12-27' UNION ALL
            SELECT  1128,124,'2010-12-27' UNION ALL
            SELECT  1128,125,'2010-12-27'
            ),
            q AS
            (
            SELECT  t.*, intervalId - ROW_NUMBER() OVER (PARTITION BY providerId, date ORDER BY intervalId) AS sr
            FROM    mytable t
            )
    SELECT  providerId, date, MIN(intervalId), MAX(intervalId)
    FROM    q
    GROUP BY
            date, providerId, sr
    ORDER BY
            date, providerId, sr
    
    1128  2010-12-27  108  114
    1128  2010-12-27  120  125
    

    , i. e. exactly what you were after.

    Are you sure you are using the query correctly? Are you having duplicates on (providerId, intervalId, date)?

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

Sidebar

Related Questions

In SQL Server 2008, I have a table with following columns and data Date
I have a table with following columns: ContractorId ......... INT ............. IDENTITY ContractorName ........
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table with following columns and data FldID | Rev | Words
Lets say I have table with following columns 1. Client - string. 2. Profit
I have a table with the following columns in SQL Server: MEMBERID, MEMBEREMAIL, FATHEREMAIL,
I have a table with the following columns: ref_year, ref_no, inv_id, start_date, end_date The
I have a table with the following columns (I simplified it a little): PRODUCT_name
I have a table with the following columns: EntityId, EntityName, EntityProfile, ................. I want
Lets say I have a table with the following columns: Qty, INTEGER SaleDate, DATETIME

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.