Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.

TSQL Challenge 27 - Identify overlapping weekly schedules of Nurses

44   Comments   

Subscribe to Notifications
  • Regarding "Can a shift extend to the next day? "

    Yes a shift can start on monday and end on tuesday. In such a case, the end time will be smaller than or equal to start time. For example 10:00-08:00 indicates that the shift starts at 10 AM and ends at 08:00 AM the next day. 0800-0800 indicates a 24 hour shift which starts at 8 am on one day and ends at 8 am the next day.

    Can there be a case where a shift starts on Sunday and the end time is smaller that the start time ?  This would mean that the shift ends on Monday:

    INSERT INTO TC27( Patient, Nurse, dy, st, en) SELECT 2000, 201, 'Sun', '2300','0200'
    
    commented on Apr 5 2010 6:04PM  .  Report Abuse This post is not formatted correctly
    None
    1217 · 0% · 20
  • Yes, a shift can start on sunday and end on monday. It is acceptable to have a shift start on sunday 2300 and end on monday morning 0200.

    commented on Apr 6 2010 2:47AM  .  Report Abuse This post is not formatted correctly
    Jacob Sebastian
    1 · 100% · 32004
  • Just to be sure everyone has understood FAQ 5, here is some tricky data and the result it should produce. They are 3 distinct cases.

    IF OBJECT_ID('TC27','U') IS NOT NULL
        DROP TABLE TC27
    GO
    CREATE TABLE TC27(
        SchID INT IDENTITY PRIMARY KEY,
        Patient INT,
        Nurse INT,
        dy CHAR(3),
        St CHAR(4),
        En CHAR(4)
    )
    
    INSERT INTO TC27( Patient, Nurse, dy, st, en)
    SELECT 2000, 201, 'Mon', '0800','1200' UNION ALL
    SELECT 2000, 201, 'Mon', '0900','1300' UNION ALL
    SELECT 2000, 201, 'Mon', '1000','1400' UNION ALL
    SELECT 2000, 201, 'Mon', '1100','1600' UNION ALL
    SELECT 2000, 201, 'Mon', '1500','1700' UNION ALL
    
    SELECT 2000, 201, 'Tue', '0800','1000' UNION ALL
    SELECT 2000, 201, 'Tue', '0900','1200' UNION ALL
    SELECT 2000, 201, 'Tue', '1100','1400' UNION ALL
    SELECT 2000, 201, 'Tue', '1300','1600' UNION ALL
    SELECT 2000, 201, 'Tue', '1500','1700' UNION ALL
    
    SELECT 2000, 201, 'Wed', '0800','1000' UNION ALL
    SELECT 2000, 201, 'Wed', '0900','1400' UNION ALL
    SELECT 2000, 201, 'Wed', '1100','1500' UNION ALL
    SELECT 2000, 201, 'Wed', '1200','1600' UNION ALL
    SELECT 2000, 201, 'Wed', '1300','1700'
    
     1 2000 201 Mon 0800 1200 No
     2 2000 201 Mon 0900 1300 Yes
     3 2000 201 Mon 1000 1400 Yes
     4 2000 201 Mon 1100 1600 Yes
     5 2000 201 Mon 1500 1700 No
    
     6 2000 201 Tue 0800 1000 No
     7 2000 201 Tue 0900 1200 Yes
     8 2000 201 Tue 1100 1400 No
     9 2000 201 Tue 1300 1600 Yes
    10 2000 201 Tue 1500 1700 No
    
    11 2000 201 Wed 0800 1000 No
    12 2000 201 Wed 0900 1400 Yes
    13 2000 201 Wed 1100 1500 No
    14 2000 201 Wed 1200 1600 Yes
    15 2000 201 Wed 1300 1700 Yes
    
    commented on Apr 7 2010 3:53AM  .  Report Abuse This post is not formatted correctly
    dishdy
    17 · 10% · 3262
  • What is the expected result for this data?

    INSERT INTO TC27( Patient, Nurse, dy, st, en)
    SELECT 2000, 201, 'Mon', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Mon', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Tue', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Tue', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Wed', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Wed', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Thu', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Thu', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Fri', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Fri', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Sat', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Sat', '2200','0200' UNION ALL
    
    SELECT 2000, 201, 'Sun', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Sun', '2200','0200'
    
    commented on Apr 7 2010 6:01AM  .  Report Abuse This post is not formatted correctly
    Leszek Gniadkowski
    8 · 18% · 5718
  • They overlap in an alternating fashion No, Yes, No, Yes,... to the end.
    The idea is that once an interval is marked as overlapping, it is 'eliminated' and can no longer participate in determining other overlaps.

    commented on Apr 7 2010 6:15AM  .  Report Abuse This post is not formatted correctly
    dishdy
    17 · 10% · 3262
  • In this case we must assume first schedule, since all schedules are overlaping.

    commented on Apr 7 2010 6:36AM  .  Report Abuse This post is not formatted correctly
    Leszek Gniadkowski
    8 · 18% · 5718
  • The answer to your question is NO, you cannot assume that only the first schedule does not overlap.
    It's true they are all overlapping 'together' - what I call a chain of overlaps.
    But maybe one way to describe the objective is that, for a single nurse, we want the largest subset of non-overlapping intervals.
    Thuse the answer should be:
    Mon 0100 2300 No
    Mon 2200 0200 Yes
    Tue 0100 2300 No
    Tue 2200 0200 Yes
    etc.

    commented on Apr 7 2010 6:53AM  .  Report Abuse This post is not formatted correctly
    dishdy
    17 · 10% · 3262
  • And for subsets with same summary period time?

    SELECT 2000, 201, 'Mon', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Mon', '2200','2000' UNION ALL
    
    SELECT 2000, 201, 'Tue', '0100','2300' UNION ALL
    SELECT 2000, 201, 'Tue', '2200','2000' UNION ALL
    

    etc.

    commented on Apr 7 2010 7:11AM  .  Report Abuse This post is not formatted correctly
    Leszek Gniadkowski
    8 · 18% · 5718
  • I don't understand your question.
    All you have changed is the end time of the 2nd and 4th period from 0200 to 2000. This will not change the result. It's still No, Yes, No, Yes,...

    commented on Apr 7 2010 7:24AM  .  Report Abuse This post is not formatted correctly
    dishdy
    17 · 10% · 3262
  • My mistake. I have use only same period.

    Another data.

    SELECT 2000, 201, 'Mon', '0800','2200' UNION ALL  - period 14h, overlap 2h left, 2h right
    SELECT 2000, 201, 'Mon', '2000','1000' UNION ALL  - same period 14h, overlap 2h left, 2h right
    

    Same start,end in Tue,Wed,Thu,Fri,Sat,Sun

    Possible results:

    Mon 0800 2200 No
    Mon 2000 1000 Yes
    Tue 0800 2200 No
    Tue 2000 1000 Yes
    


    etc.

    or

    Mon 0800 2200 Yes
    Mon 2000 1000 No
    Tue 0800 2200 Yes
    Tue 2000 1000 No
    


    etc.

    commented on Apr 7 2010 9:16AM  .  Report Abuse This post is not formatted correctly
    Leszek Gniadkowski
    8 · 18% · 5718
Previous 1 | 2 | 3 | 4 | 5 Next

Your Comment


Sign Up or Login to post a comment.

Managed Windows Shared Hosting by OrcsWeb

Copyright © Rivera Informatic Private Ltd.