• robert693 - Wednesday, February 14, 2018 1:39 PM

    Hi,
    I have a DB with PATIENT_ID, ARRIVAL_DATE, DEPARTURE_DATE, and DEPARTMENT. I need to find the average number of patients in each department per hour over a time frame. So if the date range chosen is 01/01/2018, and the end date chosen is 02/01/2018, then I need to know the average number of patients that were in each department in hours 1:00 to 23:00 over this time period. I have tried several ways but I cannot get this to work Any help would be greatly appreciated!

    Please see the following article with the understanding that you would apply the method to hours instead of months.
    http://www.sqlservercentral.com/articles/T-SQL/105968/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)