In SQL Server 2012 my (simplified) table looks like this:
Key SubKey Quantity
--------------------
96614 1 0.604800
96615 1 1.920000
96615 2 3.840000
96616 1 1.407600
96617 1 0.453600
96617 2 3.568320
96617 3 2.710260
96618 1 11.520000
96619 1 0.453600
96620 1 7.919100
96620 2 4.082400
96626 1 14.394000
96627 1 9.525600
96627 2 4.762800
96627 3 4.536000
96628 1 2.268000
My query needs to identify consecutive keys (the SubKeys are basically irrelevant) and group them into ranges, summing the Quantities appropriately. So the expected output from the above would be:
KeyRange TotalQuantity
-------------------------
96614-96620 38.47968
96626-96628 35.48640
I've tried to follow a number of examples that use window functions but I think because they are catering for different purposes they didn't make a lot of sense to me. Is this the right approach to take?