Operation average for an Equipment in the last seven days or existing records

  • Hi

    I have Table "Operations" ,This table as four columns in it..

    1. Date -its datetime

    2. Equipment -its varchar

    3. Stat -its varchar

    4. OperationHours -its real

    Date | Equipment |Stat |OperationHours

    02/17/2010 | 3102 |HH |100 <-------------- most recent by equipment 3102

    02/16/2010 | 3102 |HH |98

    02/15/2010 | 3102 |HH |92

    02/10/2010 | 3102 |HH |80

    02/17/2010 | 3105 |HR |300

    02/15/2010 | 3105 |HR |280

    02/08/2010 | 3102 |HH |75

    02/07/2010 | 3102 |HH |71

    02/10/2010 | 3105 |HR |265

    02/03/2010 | 3102 |HH |60 <--------------- seventh most recent row by equipment 3102

    I want a query that returns the average hours of operation for an Equipment and type of statistic determined from the most recent date and the seventh most recent row inserted in the table

    i.e: for the Equipment 3102 whose statistics is HH

    averageoperation=(100-60)/(02/17/2010-02/03/2010)

    averageoperation=2.85

    in the event that the Equipment has no more than seven registers must calculate the average operation with the last record entered and the first one income.

    Thanks you

  • njaramil

    If you post your table definition, sample data, expected results and what T_SQL you have tried to use, following the format as described in the first link in my signature block I am sure someone will attempt to assist you with a tested solution.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

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

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