• Alright, let's make the data a little more real world scenario.

    You have a contractor who comes by and does work as needed. You're looking for a per problem average of how long it takes for them to fix whatever issue they were brought in for. You've got a log of said person's hours:

    1/1/2000 8

    1/2/2000 4

    1/4/2000 8

    1/5/2000 8

    1/6/2000 8

    1/9/2000 3

    1/12/2000 8

    1/13/2000 8

    1/14/2000 6

    So, you need to find a way to 'group' this data, to know which sections are continuous. Using the code and teh data above, there are four distinct groups:

    1/1 - 1/2, 1/4 - 1/6, 1/9, and 1/12 - 1/14

    Now that you have them grouped, you can group on the result of the code from the article, and SUM( hours). Now you have a per group sum, which you can then average afterwards.

    This is also useful if you have non-contiguous ranges and you need to find gaps. For example, instead of grouping hours above, let's say my consultant was lax in remembering to file his paperwork. I can tell him he's missing information on 1/3, 1/7-1/8, and 1/10 - 1/12.

    There's a number of applications to this, the above simply being a couple of examples.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA