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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:22:45+00:00 2026-05-11T22:22:45+00:00

I have two tables: a schedule table that contains information about how an employee

  • 0

I have two tables: a schedule table that contains information about how an employee is scheduled and a numbers table in which each number corresponds to a date.

The tables look like:

[Employee Schedule]

ID          Employee ID Project ID  Day ID
----------- ----------- ----------- -----------
1           64          2           168
2           64          2           169
3           64          2           170
4           64          2           171
5           64          1           169
6           64          1           170
7           64          1           171
8           64          1           172
9           64          2           182
10          64          2           183
11          64          2           184

and

[Day Numbers]

ID          Day
----------- ----------
168         2009-06-18
169         2009-06-19
170         2009-06-20
171         2009-06-21
172         2009-06-22
173         2009-06-23
174         2009-06-24
175         2009-06-25
176         2009-06-26
177         2009-06-27
178         2009-06-28
179         2009-06-29
180         2009-06-30
181         2009-07-01
182         2009-07-02
183         2009-07-03
184         2009-07-04

As you can see, Employee 64 is scheduled on project 1 from 2009-06-19 to 2009-06-22 and project 2 from 2009-06-18 to 2009-06-21 and again from 2009-07-02 to 2009-07-04.

My question is: what algorithm can I use to quickly determine the spans of the employee’s schedule in a fashion such that I can display it as follows?

 Employee ID Project ID Duration
 ----------- ---------- ------------
 64          1          2009-06-19 to 2009-06-22
 64          2          2009-06-18 to 2009-06-21
 64          2          2009-07-02 to 2009-07-04

I can do this on the SQL side or the code side. I have Linq at my disposal if I need it. The table doesn’t need to be compiled by SQL. This will happen dynamically on a website and should be as efficient as possible. I don’t want to have to iterate through each and look for breaks in contiguous days if I don’t have to.

  • 1 1 Answer
  • 1 View
  • 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-11T22:22:45+00:00Added an answer on May 11, 2026 at 10:22 pm

    Assuming the Day IDs are always sequential for a partial solution…

    select *
      from employee_schedule a                    
     where not exists( select *                          
                         from employee_schedule b        
                        where a.employeeid = b.employeeid
                          and a.projectid  = b.projectid 
                          and (a.dayid - 1) = b.dayid )
    

    lists the start day IDs:

     ID      EMPLOYEEID       PROJECTID           DAYID 
     1              64               2             168 
     5              64               1             169 
     9              64               2             182 
    
    
    
    select *
      from employee_schedule a                   
     where not exists( select *                         
                         from employee_schedule b       
                        where a.employeeid = b.employeei
                          and a.projectid  = b.projectid
                          and (a.dayid + 1) = b.dayid )
    

    lists the end day IDs:

      ID      EMPLOYEEID       PROJECTID           DAYID 
      4              64               2             171 
      8              64               1             172 
     11              64               2             184 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, TABLE_1 and TABLE_2 . TABLE_1 contains ID and NAME ,
I have project which contain 4 tables among these shedule table Session column i
I have a google doc spreadsheet that contains information on every member of a
I Have a Table (Accommodation) with All information about a holiday home. Inc ID
I have recently added an intermediary table to link two tables. Tables: Purchase: Transaction_Id
I have a table of schedule items, they may be scheduled for the same
I have a table which holds flight schedule data. Every schedule have an effective_from
I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have two tables: Companies and Employees. I also have a relation table Employs
I have a view controller that contains a table view, the items in the

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.