• Question: If a staff member works with 2 patients at the same time, for the last 15 minutes of the work with patient1, and those 15 minutes are also the first 15 minutes of working with patient2, how much total time needs to be logged for this staff member ? I would think that wherever there's overlap, it would be from the beginning of the overall time window to the end thereof. However, you asked for data only for when there is no overlap. Is that indeed what you want? If so, try this and see if that gets you what you're looking for:

    SELECT SD.STAFF_ID, SD.SERVICE_DATE, SUM(SD.ELAPSED_MINUTES) AS TTL_TIME

    FROM STAFF_DATA AS SD

    GROUP BY SD.STAFF_ID, SD.SERVICE_DATE

    WHERE NOT EXISTS

    (SELECT 1 FROM STAFF DATA AS S2

    WHERE S2.STAFF_ID = SD.STAFF_ID

    AND S2.SERVICE_DATE = SD.SERVICE_DATE

    AND S2.BEGIN_TIME < SD.END_TIME

    AND S2.END_TIME >= SD.END_TIME

    )

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)