pls help newbie re averaging values hourly

  • I need to create sql statement wherein if I feed the following table fields as input parameters:

    Channel_Date, Ch_A, Ch_B, Ch_C, Ch_D

    and I also feed @startdate and @enddate params

    it will give me Channel_Date values showing every hour on the hour, then each subsequent fields showing AVERAGE val for each given hour (e.g. avg of values from 1:00 thru 1:45). The date value for Channel date currently are on 15-minute intervals e.g. 1/1/2011 1:00 AM, 1/1/2011 1:15, 1/1/2011 1:30.. and so forth.

    All field(s) are part of one table being queried. Channel_Date is datetime value, other fields are real datatype vals.

    Sample Output:

    Channel_Date, Avg_Ch_A, Avg_ChB, ...

    1/1/2011 1:00, {avg val), {avg val}

    1/1/2011 2:00, {avg val), {avg val}

    1/1/2011 3:00, {avg val), {avg val}

    Thank you for sharing your expertise.

    UPDATE:

    After hours and hours of scouring around, the closest solution I found is here:

    http://www.sqlservercentral.com/Forums/Topic313278-8-1.aspx

    I hope this can help others... Peace

  • Maybe you can use a pivot tables in SQL Server

  • Your narrative is great but you might want to check the first link in my signature line below to get better help in the future.

    --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)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply